SSHexit code > 0

Connection refused (SSH)

$ssh: connect to host example.com port 22: Connection refused

Analysis

The SSH client could not establish a TCP connection to the server on port 22.

Common Triggers

  • SSH server (sshd) is not running.
  • Firewall blocking port 22.
  • Wrong IP address or hostname.

Debug Checks

  • $Check if you can ping the host.
  • $Run nc -zv host 22 to test connectivity.

Resolution

1
Start the SSH service on the server.
2
Allow port 22 through the firewall.
3
Verify the hostname and IP address.