Skip to content

SSH hardening on Linux — the changes that actually matter

A short list of SSH server changes that meaningfully reduce risk on production Linux, and the ones that show up in checklists but barely move the needle.

Most SSH hardening guides are a long list of sshd_config directives, half of which are defaults on modern distributions. The handful of changes that actually reduce exposure on a production server is short, and worth getting right before the rest.

What’s happening

A fresh Linux install in 2026 already ships with password authentication enabled, root login permitted, and broad ciphers. Internet-facing SSH on default port 22 will see automated login attempts within minutes of the first DNS resolution. The risk is not that an attacker brute-forces an ed25519 key — it’s that a forgotten user with a weak password, or a stale CI key copied into authorized_keys years ago, is still valid.

How to verify

Inspect what the server is actually accepting:

sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|kbdinteractive|pubkeyauth|allowusers|allowgroups|ciphers|macs|kexalgorithms'

Then audit the active credentials:

sudo find /home /root -name authorized_keys -exec ls -la {} \; -exec cat {} \;
sudo lastlog | awk '$2 != "**Never" && $2 != "Username"'
sudo awk -F: '($2 != "*" && $2 != "!" && $2 != "!!") {print $1}' /etc/shadow

Any key you can’t trace to a current human or system is a candidate for removal. Any account with a usable password that does not need one is a candidate for passwd -l.

The fix

The four changes that meaningfully reduce risk:

PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
AllowGroups ssh-users

Then create the ssh-users group, add only accounts that need SSH, and confirm with getent group ssh-users. Reload with systemctl reload sshd — never restart on a remote session before validating in a second connection.

Beyond that, prefer hardware-backed keys (ssh-keygen -t ed25519-sk) for human operators, set MaxAuthTries 3, and run sshd on a non-default port only if you also remove port 22 from the firewall — running on both is theatre. Rotate authorized_keys content on a known cadence, not when someone leaves.

If the server faces the public internet, pair this with a fail2ban policy and rate-limited firewall rules; the SSH config alone is necessary, not sufficient.

We treat SSH baseline, key rotation, and access reviews as part of every long-lived environment under Deployment & Management.