The error: SSH connection attempts either get refused outright or hang indefinitely with no response, even though the server is confirmed running and reachable via ping.
Environment: Any Linux server running sshd.
Why this happens: "Connection refused" and "hangs with no response" point at genuinely different layers, which is the first thing worth separating before troubleshooting further. Refused means something actively rejected the connection (sshd not running, or a firewall sending an active reject). Hanging with no response usually means a firewall is silently dropping the packets rather than rejecting them — or, less commonly, that fail2ban or a similar tool has actively banned the connecting IP after prior failed attempts.
The fix:
- Confirm sshd is actually running:
systemctl status sshd. - Check local firewall rules:
firewall-cmd --list-alloriptables -L -n, confirming port 22 (or whatever port SSH is configured on) is actually allowed. - If a specific IP is failing while others work, check fail2ban specifically:
fail2ban-client status sshdwill show currently banned addresses. - Check
/etc/hosts.allowand/etc/hosts.denyif those are in use — an older but still-functional access control mechanism that's easy to forget exists.
One thing worth knowing: a fail2ban lockout after a bad password attempt (your own typo, testing a script, whatever) looks identical to a firewall problem from the outside — check fail2ban status early rather than assuming it's a config issue on the server side.