OGOPSEC // Dispatch
SSH Hardening: A Checklist That Moves the Needle
SSH hardening is one of those topics where every guide hands you forty settings and no sense of which ones matter. The truth is that a handful of changes carry almost all of the risk reduction, and the rest are either situational or cosmetic. This post is the short, ordered checklist we actually use, with a plain statement of what each step buys you and where it stops.
Everything below lives in /etc/ssh/sshd_config (or a drop-in under /etc/ssh/sshd_config.d/). Before you change anything, one rule that will save your afternoon: keep your current session open, apply changes, then open a second connection to confirm you can still get in. Never restart sshd and close your only session on faith.
Step 1: Move to key-only authentication
This is the single highest-value change in any SSH hardening effort. Passwords can be guessed, sprayed, and phished; a keypair cannot be brute-forced over the network. Generate a modern key on your client if you do not have one:
ssh-keygen -t ed25519 -C "you@workstation"
ssh-copy-id you@server
Once your key works, disable password authentication on the server:
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
What it buys you: it eliminates the entire category of password-guessing attacks that make up most of the noise in any server's auth log. Where it stops: it does nothing about a stolen or copied private key. A key sitting unencrypted on a compromised laptop is a password with extra steps. Protect the key with a passphrase, or anchor it to hardware (more on that in our two-factor SSH post).
Step 2: Constrain root
Direct root login over SSH turns one guessed or stolen credential into total control, and it erases the audit trail of who did something. Require administrators to log in as themselves and escalate with sudo:
PermitRootLogin no
If you genuinely need automated root access for a backup or orchestration tool, use prohibit-password instead of yes, so root is reachable only by key, never by password.
Step 3: Limit who can connect at all
By default, every account on the box is a potential SSH entry point, including service accounts you forgot existed. An allow-list collapses that surface to the handful of people who should be connecting:
AllowUsers alice bob
# or, by group:
AllowGroups ssh-users
Honest limit: this is an authorization gate, not an authentication one. It decides who is permitted to try, not whether their credential is valid. It pairs with Step 1; it does not replace it.
Step 4: Reduce the blast radius of a bad session
A few settings make a compromised or idle session less useful to an attacker:
ClientAliveInterval 300andClientAliveCountMax 2— reap dead or abandoned sessions instead of leaving them open.LoginGraceTime 20— close the window in which an unauthenticated connection can sit and consume resources.MaxAuthTries 3— stop a single connection from making dozens of attempts.X11Forwarding noandAllowTcpForwarding no— turn off forwarding you are not using; both are useful footholds for lateral movement.
Step 5: Rate-limit the noise
You will still see connection attempts; the public internet scans everything. A tool like fail2ban or the newer per-source limits in OpenSSH reduce the volume and slow down anyone methodical:
PerSourceMaxStartups 3:50:10
What it buys you: quieter logs and slower attackers. What it does not do: stop a determined, distributed effort. Rate limiting is friction, not a wall. If Steps 1–3 are in place, the friction is almost beside the point, which is exactly the right order of priorities.
What SSH hardening does and doesn't protect against
Done well, the checklist above closes the network-facing doors that attackers actually knock on: password guessing, anonymous root access, and forgotten accounts. That is the bulk of real-world SSH compromise.
It does not protect you from a stolen private key, a backdoored client, a malicious insider with a valid account, or a vulnerability in the SSH daemon itself (keep it patched). Hardening narrows the front door; it is not a substitute for endpoint security on the machines that hold your keys, nor for watching your auth logs.
Security you can check means stating the threat model out loud. SSH hardening defends against remote credential attacks. It says nothing about whoever already holds a legitimate key.
A note on anchoring the credential
Because the residual risk after hardening concentrates in the private key, the highest-leverage next move is to make that key impossible to silently copy. Hardware-backed keys — a FIDO2 security key, or a device-bound credential like Dire Wolf, which keeps the key material on a TPM-anchored USB token and refuses to export it — turn "stolen key file" back into "needs the physical device." That is the honest end state of SSH hardening: the network is closed, and the secret lives somewhere a remote attacker cannot reach.