SSH keys, and letting fail2ban do the shouting

← Field Notes

Every small server on the internet gets its SSH port knocked on, constantly. The knocks are not personal and they are not going to stop, so the goal is not silence — the goal is a setup where the knocks do not matter and the log stays readable enough that a real problem stands out.

Step one: keys only

Generate a key pair, copy the public key over, log in with it once to be sure, and only then set PasswordAuthentication no. Doing it in that order matters. I once did it in the other order on a machine with no console access; that is a story I only tell once.

Step two: a plain fail2ban jail

The stock sshd jail is enough for a personal box: a handful of failed attempts earns a day-long ban. The point is not to stop a determined attacker — keys do that — the point is to keep auth.log from filling up with noise, so when I grep it I see my own logins and nothing else.

Step three: leave the port alone

Moving SSH to a high port reduces noise but adds a thing to remember on every client. With keys-only login and the jail running, standard port 22 plus a firewall that only opens what is needed has been the calmest setup I have run. Boring wins again.