Homelab

SSH Connection Refused vs. Connection Timed Out

A refusal points to a connection that was actively rejected. A timeout means the client waited without completing it. Test the same host and port before you change SSH keys or settings.

Read the last line printed by ssh. Connection refused and Connection timed out happen before you can authenticate. If you see Permission denied (publickey), SSH has already reached the authentication stage. The exact error tells you which layer to check first. DigitalOcean SSH connectivity guide.

1. Test the host and port SSH actually uses

Use TCP/UDP Connect with protocol TCP and the port from the failed command or SSH configuration. The default is 22. Run the check from the device and network that have the problem, including the same VPN if one is required. If SSH uses a jump host, test the first hop from your device and the destination from the jump host's network.

OpenSSH's verbose output shows the destination address and port. This example uses a five-second connection timeout so repeated diagnostics are easy to compare. Substitute your username, hostname, and port.

ssh -v -o ConnectTimeout=5 -p 22 [email protected]

If the name resolves to multiple addresses, test the expected IP directly in TCP/UDP Connect and compare it with the address SSH reports. A stale DNS record or an unreachable IPv6 address can send your test somewhere different from the working client. DNS Lookup.

If your server listens on a custom SSH port, put that port in the test. This example opens a TCP check for port 2222 on a LAN server.

https://netdebug.app/open/portconnect?target=192.168.50.20&port=2222&protocol=tcp&autorun=false

Test the SSH port directly

Enter the same host and port as the failed SSH command. Compare the TCP result from the affected network and a connection that normally works.

Get NetDebug Toolkit

2. If it's refused, check the listener

A refusal usually means the client received a TCP reset. A host can return a reset when there's no listener on that address and port, and a firewall can reject a connection the same way. Check the listener before adjusting access rules.

On a Linux server you manage, open its console or an existing session and list listening TCP sockets. Compare the port and local address with the failing request.

ss -ltn
  • If the intended port is absent, check the SSH service status and logs. The service may be named ssh or sshd, depending on the distribution.
  • If the listener is on 127.0.0.1 or ::1, it accepts only local connections. Check which interface or address the server should listen on.
  • If the port and address match, inspect the host firewall for an explicit reject and confirm that the address really belongs to this server.

OpenSSH uses Port and ListenAddress to configure its listener. If you change them, keep your current access open while you verify the new connection. OpenSSH server configuration reference.

3. If it times out, follow the network path

Test the port from a client on the same network as the server, then test from the affected connection. Success on the LAN and a timeout over VPN point to differences along that path. Check the client's route, VPN access rules, and whether the server or its gateway can route the reply back.

For a server in a cloud network, check the provider firewall or security group as well as the host firewall. For a server you reach through a router you manage, confirm the forwarding rule targets the current LAN IP and the intended TCP port. Port forwarding troubleshooting.

If TCP connects but the SSH client still stalls, read the verbose output to see whether it received a server banner or began key exchange. A reachable port is the start of the SSH session. The server logs can tell you what happened afterward.

Frequently asked questions

Why can I ping a server but get SSH connection refused?

Ping and SSH use different protocols. The host can answer an ICMP echo while its SSH port has no listener or a firewall rejects the TCP connection.

Does a timeout mean a firewall is blocking SSH?

A silent firewall drop is one possibility. A wrong address, missing route, offline host, or broken return path can produce the same result. Compare a direct LAN test with the failed path.

What if the TCP port opens but SSH says permission denied?

The connection has reached authentication. Check the SSH username, key offered by the client, and server authentication policy.