Security boundaries / 2026-05-03
SSH hardening checklist: from port to second factor
On a public host, SSH is the most scanned entry point. This list is ordered by payoff, not by habit.
A public host gets scanned hundreds of times a day. Those Failed password for root lines are not aimed at you — they are automation sweeping the whole internet. The goal of hardening is not "never get noticed", it is "being noticed does not help them".
Priority one: kill password login
Highest payoff by far; it removes essentially all brute-force traffic.
# /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin prohibit-password
KbdInteractiveAuthentication no
Validate with sshd -t, then systemctl reload sshd. Keep the current session open, test key login from a second window, and only close the old one once the new one works.
Priority two: restrict the source
ufw allow from 10.0.0.0/8 to any port 22
ufw allow from <your-fixed-ip> to any port 22
ufw default deny incoming
Without a fixed IP, reach the host over WireGuard first and SSH inside the tunnel. That beats exposing port 22 to the planet.
Priority three: trim forwarding
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
MaxAuthTries 3
LoginGraceTime 30
AllowTcpForwarding no has a side effect: if you use SSH tunnels for local debugging of remote services, you need an exception or another channel.
The order most people get wrong
Changing the port and installing fail2ban first feels productive but is backwards. Ranked by payoff: disable direct root login, disable password auth, restrict source IPs, then change the port (noise reduction, not security), then fail2ban as a backstop. After the first two, the brute-force log usually goes to zero.
AllowUsers deploy is a whitelist and therefore safer than DenyUsers — it denies by default.
Verify the key before you reload
ssh -i ~/.ssh/id_ed25519 deploy@server 'echo ok'
If that fails, do not restart sshd. The classic lockout is: edit config, reload, discover the key was never installed correctly.
Keep a way back in
Cloud VNC or rescue mode is the real fallback. A temporary self-reverting change can help when you still have console access:
(sleep 600; sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config; systemctl reload ssh) &
That is an emergency measure, not a policy.
Checklist
- [ ] Password login off, keys work, console fallback exists
- [ ] Port or source restricted — not "the whole world on 22"
- [ ] Forwarding and X11 off unless explicitly needed
- [ ] Failed attempts get banned
- [ ] An out-of-band way in (VNC / serial / provider console)
The last item is the one people skip. Every hardening step assumes you can still get in; when you cannot, none of the rest matters.
journalctl -u ssh --since "-24h" | grep -c "Failed password"
That number is your scan rate. After hardening it should be near zero; if it keeps climbing, something is still authenticating with a password — usually an automation script that needs its own fix.