Harden the SSH server
Updated 27 Nov 2026 ssh hardening
Turn off password sign-in, limit who can connect and check before reloading.
Check that signing in with your SSH key works first. Keep one session open while you change SSH, and test with a second one.
Settings
Create /etc/ssh/sshd_config.d/00-hardening.conf:
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
MaxAuthTries 3
LoginGraceTime 30
X11Forwarding no
AllowUsers root deploy
prohibit-password lets root sign in with a key only. Use no once another account with sudo works. List every account that must be able to sign in under AllowUsers, or remove that line if you prefer not to restrict by name.
Check and apply
sudo sshd -t
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin'
sudo systemctl reload ssh # "sshd" on AlmaLinux and Rocky
The second command shows the effective values. The first file read wins, so an earlier file can override yours.
Changing the port
On a shared-IPv4 plan the forwarded SSH port reaches port 22 inside your server. Moving SSH to another port inside the server breaks that mapping. Leave it on 22.
Keys
Use Ed25519 keys with a passphrase and remove keys of people who have left from ~/.ssh/authorized_keys.
Locked out?
Use the browser console.