Secure Your Linux Server: 8 Essential SSH Hardening Steps
Learn how to protect your Linux server by disabling root SSH login, changing the default port, enforcing strong passwords, limiting login attempts, using SSH protocol 2, disabling forwarding, employing key‑based authentication, and restricting access by IP, with clear commands and configuration examples.
Why Secure SSH?
SSH is a widely used protocol for securely accessing Linux servers, but its default configuration can expose serious security risks, especially when root login is allowed over a public IP address.
1. Disable Root Login
Create a new user with sudo privileges and prevent root from logging in via SSH.
useradd -m exampleroot
passwd exampleroot
usermod -aG sudo examplerootThen edit /etc/ssh/sshd_config:
#Authentication:
#LoginGraceTime 2m
PermitRootLogin no
AllowUsers examplerootRestart the SSH service:
sudo systemctl restart ssh2. Change the Default Port
Modify the SSH listening port to make automated attacks harder. Port 22099 After editing /etc/ssh/sshd_config, restart SSH:
sudo systemctl restart ssh3. Disallow Empty Passwords
Prevent users without passwords from logging in.
PermitEmptyPasswords no4. Limit Login Attempts
Set a maximum number of authentication attempts to mitigate brute‑force attacks.
MaxAuthTries 35. Use SSH Protocol 2
Enable the more secure SSH protocol version.
Protocol 26. Disable TCP and X11 Forwarding
Turn off port forwarding and X11 forwarding to reduce attack surface.
X11Forwarding no
AllowTcpForwarding no7. Use SSH Key Authentication
Generate a key pair and configure the server to accept only key‑based logins. ssh-keygen Upload the public key to ~/.ssh/authorized_keys on the server and optionally disable password authentication in sshd_config.
8. Restrict SSH Access by IP
Use /etc/hosts.allow (or firewall rules) to allow only trusted IP ranges and deny all others.
# Example entry in hosts.allow
sshd: 192.168.1.0/24 : allow
sshd: ALL : denyAfter making changes, restart the SSH service to apply them.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
