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.

· 2 min read · intermediate

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:

bash
ssh-keygen -t ed25519 -C "you@device"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server

Confirm key login works, then in /etc/ssh/sshd_config:

nginx
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes

2. 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:

nginx
PermitRootLogin no

3. Limit who can connect

Be explicit about which accounts may use SSH at all:

nginx
AllowUsers deploy alice

4. Apply the reflexive defaults

nginx
Protocol 2
X11Forwarding no
AllowAgentForwarding no
MaxAuthTries 3
LoginGraceTime 20
ClientAliveInterval 300
ClientAliveCountMax 2

Validate the config before reloading — this catches typos that would otherwise break the service:

bash
sudo sshd -t && sudo systemctl reload ssh

5. 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:

bash
sudo apt install fail2ban
# the default [sshd] jail is enabled out of the box on most distros
sudo fail2ban-client status sshd

6. 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

nginx
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowUsers deploy
MaxAuthTries 3
LoginGraceTime 20
X11Forwarding no
AllowAgentForwarding no
ClientAliveInterval 300
ClientAliveCountMax 2

Takeaways

  • Keys-only auth is the one change that matters most — it ends brute-forcing.
  • PermitRootLogin no + AllowUsers shrink the attack surface to almost nothing.
  • Always sshd -t and test a new session before closing your current one.
  • Best of all: hide SSH behind a VPN so it's never exposed.

Related

Linux beginner

Essential Shell One-Liners

The pipes and filters that turn the terminal into a power tool — find, grep, sort, awk and xargs, composed into commands you'll reuse daily.

· 2 min read