Knowledge base / Linux & server administration

Hardening SSH access on Linux servers

Every internet-facing server gets thousands of SSH login attempts a day. These settings make them harmless.

In /etc/ssh/sshd_config

PermitRootLogin prohibit-password   # or "no" if you use sudo users
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowUsers alice bob rakar

Make sure your key login works in a second session before you reload: sshd -t && systemctl reload sshd. Keep the first session open until you've tested.

Also