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.

Open Source Linux
Open Source Linux
Open Source Linux
Secure Your Linux Server: 8 Essential SSH Hardening Steps

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 exampleroot

Then edit /etc/ssh/sshd_config:

#Authentication:
#LoginGraceTime 2m
PermitRootLogin no
AllowUsers exampleroot

Restart the SSH service:

sudo systemctl restart ssh

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

3. Disallow Empty Passwords

Prevent users without passwords from logging in.

PermitEmptyPasswords no

4. Limit Login Attempts

Set a maximum number of authentication attempts to mitigate brute‑force attacks.

MaxAuthTries 3

5. Use SSH Protocol 2

Enable the more secure SSH protocol version.

Protocol 2

6. Disable TCP and X11 Forwarding

Turn off port forwarding and X11 forwarding to reduce attack surface.

X11Forwarding no
AllowTcpForwarding no

7. 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 : deny

After making changes, restart the SSH service to apply them.

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.

firewallLinuxHardeningportKeyAuthenticationRootLogin
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.