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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Secure Your Linux Server: 8 Essential SSH Hardening Steps

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 exampleroot

Then edit /etc/ssh/sshd_config to include:

#Authentication:
#LoginGraceTime 2m
PermitRootLogin no
AllowUsers exampleroot

Restart the SSH service:

sudo systemctl restart ssh

2. 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 2

6. Disable TCP and X11 forwarding

Prevent port and X11 forwarding attacks by setting:

X11Forwarding no
AllowTcpForwarding no

7. Use SSH key authentication

Generate a key pair with ssh-keygen, place the public key on the server, and optionally disable password authentication.

ssh-keygen

8. Restrict SSH access by IP

Edit /etc/hosts.allow to allow specific IP ranges or addresses and deny all others.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Server HardeningLinux securitySSHssh-config
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.