Encountering an ssh connect to host connection refused message is one of the most common and frustrating issues system administrators and developers face. This specific error indicates that your client successfully reached the network path to the target server, but the SSH daemon was not available to accept the connection at the specified port. Unlike a timeout, which suggests the host is unreachable, a connection refusal signals that something is actively blocking the service on the other end.
Decoding the "Connection Refused" Error
The phrasing of the error provides the first critical clue for troubleshooting. If you see "ssh: connect to host example.com port 22: Connection refused," it means your SYN packet was responded to with a RST (reset) packet rather than a SYN-ACK. This usually happens when no process is listening on that specific port or the host's firewall is dropping packets in a way that mimics refusal. Understanding this network behavior is essential because it directs your investigation away from basic connectivity checks and toward service and configuration issues.
Initial Service Verification
Before diving into complex firewall rules, you should verify the obvious: Is the SSH service actually running on the remote machine? If you have console access or another management channel, you need to check the status of the daemon immediately. A stopped service is the most straightforward explanation for an ssh connect to host connection refused scenario, and it can occur due to a recent system crash, a failed update, or manual intervention.
Checking the SSH Daemon Status
Use systemctl or service commands to verify the current state of sshd.
Review recent logs in /var/log/auth.log or /var/log/secure for crash signals.
Ensure the daemon is configured to start automatically on boot to prevent future outages.
Firewall and Network Filtering Issues
Once you confirm the service is running, the next likely culprit is a misconfigured firewall. Administrators often block incoming traffic on port 22 to deter brute-force attacks but forget to add the specific rule to allow their management IP. A firewall dropping packets silently can sometimes result in a refusal if the host iptables or cloud security group is explicitly rejecting the connection rather than just ignoring it.
Common Firewall Culprits
Configuration Drift and Port Misalignment
Another frequent cause of ssh connect to host connection refused is a mismatch in the SSH port configuration. The remote server might be configured to listen on a non-standard port, perhaps due to security hardening guidelines or a previous troubleshooting session. If your client attempts to connect on the default port 22 while the daemon is listening on 2222 or another number, the operating system will return a refusal because nothing is bound to that specific socket.
Verifying the Correct Port
Check the sshd_config file for the "Port" directive.
Use netstat or ss to see which ports the daemon is actually listening on.
Always specify the port explicitly using the -p flag in your SSH command.