A listener
ss -tlnp shows sshd bound to 0.0.0.0 or ::. Binding to loopback or a private interface removes the internet path entirely.
Port 22 answers from the public internet, authorized_keys has grown for years, and nobody can say which key still works. The fix is not a stronger password policy: it is an inventory, one path in, and an audit trail you can read after the fact.
This page is free. It covers detection, the order that closes the exposure without locking yourself out, and the checks that prove the change held. It contains no attack steps.
ss -tlnp shows sshd bound to 0.0.0.0 or ::. Binding to loopback or a private interface removes the internet path entirely.
Keys are not automatically safer if password auth is still on for one group, or if root can log in with a key that was copied to a laptop.
Every key in every authorized_keys is a standing credential. It survives staff departures, laptop resets and CI images unless someone removes it.
A jump host, a VPN or a Cloudflare Tunnel is only a control if the origin port is unreachable from outside. Otherwise it is a second door.
| Command | What it tells you |
|---|---|
| ss -tlnp | grep ':22' | Which address sshd listens on, and which process owns it. |
| sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication|allowusers|allowgroups|maxauthtries)' | Effective global config, including defaults that were never written down. |
| sshd -T -C user=deploy,host=example,addr=203.0.113.10 | Effective config for one connection, after Match blocks. This catches the exception everyone forgot. |
| find /home /root -name authorized_keys -exec ssh-keygen -lf {} + | Every key with its fingerprint, type and size, per account. |
| wc -l /home/*/.ssh/authorized_keys | How many standing credentials exist, and in whose home. |
| last -a | head -20; lastb | head -20 | Recent successful and failed logins, with source addresses. |
| journalctl -u ssh -u sshd --since '7 days ago' | grep -E 'Accepted|Failed|Invalid user' | Auth events. Empty output usually means the unit name is wrong, not that nobody tried. |
| cloudflared tunnel list | Tunnels that could publish SSH; confirm the hostname sits behind an Access policy. |
| # | Failure mode | What you see | What to do |
|---|---|---|---|
| 1 | The public listener is still the real path | ss shows 0.0.0.0:22 while the team says "we only use the tunnel". | Bind sshd to loopback or a private interface, allow 22 only from the tunnel or management network, and verify from an external network. |
| 2 | A Match block re-enables password auth | The global config says no; sshd -T -C ... says yes for one group. | Remove the override or scope it to a network that cannot reach the internet; test with ssh -o PreferredAuthentications=password. |
| 3 | Key sprawl with no restrictions | Thirty keys in one file, none with from= or restrict; nobody knows which laptop owns a fingerprint. | Inventory by fingerprint, re-issue with from= or restrict, remove the rest, and add a review date to the file. |
| 4 | The audit trail is local and short | journalctl is volatile, auth logs rotate in days, and nobody recorded the session. | Enable persistent journal storage, ship auth logs off-host, and record sessions at the access layer. Do this before the incident. |
| 5 | fail2ban is treated as the control | Hundreds of banned IPs, but one leaked key still works and never triggers a ban. | Fix keys and the network path first. Bans reduce log noise; they do not authenticate anyone. |
| 6 | Agent forwarding and shared jump hosts | ForwardAgent yes on a laptop, root's agent socket reachable on a shared bastion. | ForwardAgent no, per-host keys, ssh -J with -o IdentitiesOnly=yes, and no shared root account. |
Dump listeners, effective config, keys and recent logins before changing anything. You need a baseline and a second way in.
Bind to loopback or private, put the tunnel or VPN in front, and block 22 at the edge. Keep an out-of-band console.
PasswordAuthentication no, KbdInteractiveAuthentication no, PermitRootLogin no. Run sshd -t before any reload.
From a network you do not control, confirm the port is closed and the tunnel path enforces the Access policy. Then confirm the login appears in the audit trail.
cloudflared access ssh --hostname ssh.internal puts the connection through Cloudflare Access; the policy decides who can reach port 22 on the origin. The origin still authenticates the SSH user, so keys and AllowUsers still matter.
A tunnel token can publish routes. Scope it to the tunnel, rotate it, and do not leave a second copy on a laptop. A token in a shell history is the same as a key in a public repo.
| Check | Expected result |
|---|---|
| ss -tlnp | grep ':22' | Loopback or a private address only; no 0.0.0.0 or ::. |
| ssh -o ConnectTimeout=5 -o BatchMode=yes user@host from an external network | Timeout or connection refused, not an SSH banner. |
| sshd -T -C user=...,host=...,addr=... | passwordauthentication no for every user and group that matters. |
| journalctl -u ssh --since -1h after a test login | The event is present with the source address, and it is shipped off-host. |
Only if the public port is closed. A VPN in front of an open sshd is a second door; check from outside the VPN before you call it done.
If you must, scope it to a management network and an account without sudo, and alert on every use. A global yes is not break-glass.
No. That is why an inventory and a removal date matter more than key length. A five-year-old key on a lost laptop is still valid today.
It reduces log noise, not exposure. Treat it as cosmetic unless the port is also unreachable from the internet.
The paid runbooks cover the change windows around this: production defaults, certificate rollovers, and the checks that fail only on a real domain.
This page is free, no checkout. Paid runbooks are $9.99 each and covered by the 7-day refund policy at /runbooks/refund.