Harden OpenSSH on Linux Servers (Secure sshd_config)

harden openssh linux linux-openssh-harden.png

Internet-facing Linux servers need a locked-down OpenSSH configuration. Apply these sshd_config changes after confirming key-based login works.

Step 1: Confirm SSH Key Login Works

Before disabling passwords, verify ssh user@server works with your key from a second session.

ssh key authentication before hardening openssh linux
Step 1: Confirm SSH Key Login Works

Step 2: Edit sshd_config

Set PermitRootLogin no, PasswordAuthentication no, and optionally AllowUsers deploy.

sshd_config PermitRootLogin PasswordAuthentication linux
Step 2: Edit sshd_config

Step 3: Validate and Reload sshd

Run sshd -t then systemctl reload sshd. Keep your current SSH session open as a fallback.

sshd -t reload sshd linux hardening
Step 3: Validate and Reload sshd

Recommended settings

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowUsers deploy admin

Related tutorials

Terminal screenshots are original illustrations created for Gnome IT Solutions (blog.gnomeitsolutions.com).