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.
SSH is a widely used protocol for securely accessing Linux servers, but default settings can expose security risks.
Servers with open SSH root access are vulnerable, especially when reachable via a public IP, so strengthening SSH is essential.
1. Disable root login
Create a new user with sudo privileges and disable root SSH access.
useradd -m exampleroot
passwd exampleroot
usermod -aG sudo examplerootThen edit /etc/ssh/sshd_config to include:
#Authentication:
#LoginGraceTime 2m
PermitRootLogin no
AllowUsers examplerootRestart the SSH service:
sudo systemctl restart ssh2. Change the default port
Modify /etc/ssh/sshd_config to use a non‑standard port, e.g., 22099. Port 22099 Restart SSH and adjust firewall rules accordingly.
3. Disallow empty passwords
Set PermitEmptyPasswords no in sshd_config to block users without passwords.
4. Limit login attempts
Configure MaxAuthTries 3 to terminate connections after three failed attempts.
5. Use SSH protocol version 2
Enable the more secure protocol by adding:
Protocol 26. Disable TCP and X11 forwarding
Prevent port and X11 forwarding attacks by setting:
X11Forwarding no
AllowTcpForwarding no7. Use SSH key authentication
Generate a key pair with ssh-keygen, place the public key on the server, and optionally disable password authentication.
ssh-keygen8. Restrict SSH access by IP
Edit /etc/hosts.allow to allow specific IP ranges or addresses and deny all others.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
