An SSH Hardening Checklist That Actually Moves the Needle
The handful of sshd settings and habits that stop the overwhelming majority of SSH attacks — keys over passwords, sane defaults, and verifying before you lock yourself out.
An internet-facing SSH port gets scanned and brute-forced constantly. The good news: a short list of changes removes almost all of that risk. Here is the list, in priority order.
1. Use keys, disable password auth
This single change defeats brute-forcing outright. Generate a modern key:
ssh-keygen -t ed25519 -C "you@device"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@serverConfirm key login works, then in /etc/ssh/sshd_config:
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes2. Don't let root log in directly
Log in as a normal user and escalate with sudo. This gives you accountability (who did what) and removes the single most-targeted username:
PermitRootLogin no3. Limit who can connect
Be explicit about which accounts may use SSH at all:
AllowUsers deploy alice4. Apply the reflexive defaults
Protocol 2
X11Forwarding no
AllowAgentForwarding no
MaxAuthTries 3
LoginGraceTime 20
ClientAliveInterval 300
ClientAliveCountMax 2Validate the config before reloading — this catches typos that would otherwise break the service:
sudo sshd -t && sudo systemctl reload ssh5. Rate-limit and ban the noise
fail2ban watches the auth log and temporarily bans IPs that fail repeatedly. It won't stop a determined attacker, but it silences the background brute-force roar and shrinks your logs:
sudo apt install fail2ban
# the default [sshd] jail is enabled out of the box on most distros
sudo fail2ban-client status sshd6. Consider moving the port (cosmetic, but quieter)
Changing from 22 to something else does not add real security — a scanner finds it in seconds — but it dramatically cuts log noise from untargeted bots. Treat it as housekeeping, not defence.
7. The real win: don't expose it at all
The strongest option is to keep SSH off the public internet entirely and reach it through a VPN (WireGuard, Tailscale) or a bastion host. An attacker can't brute-force a port they can't see.
A sane baseline, all together
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowUsers deploy
MaxAuthTries 3
LoginGraceTime 20
X11Forwarding no
AllowAgentForwarding no
ClientAliveInterval 300
ClientAliveCountMax 2Takeaways
- Keys-only auth is the one change that matters most — it ends brute-forcing.
PermitRootLogin no+AllowUsersshrink the attack surface to almost nothing.- Always
sshd -tand test a new session before closing your current one. - Best of all: hide SSH behind a VPN so it's never exposed.