SSH "Connection Refused" vs "Connection Closed": Different Bugs

Symptom

ssh fails; wording of the error is the clue.

Root cause

Refused = nothing listening on that port. Closed = something listened, then killed the handshake.

Fix, in order

1. Refused: check sshd and the portsystemctl status sshd && ss -tlnp | grep :22
2. Closed: read the server log for the reasontail -20 /var/log/auth.log # MaxStartups? AllowUsers?
3. Both: verify no firewall middlemannc -vz host 22

Prevent it coming back

Keep an out-of-band console path so SSH is never your only way in.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Managed cloud hosting

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog