ssh: connect to host port 22: Connection timed out

Connection timed out means your SYN packets got no reply: a firewall dropped them, the host is down, or you have the wrong address. It is different from Connection refused, which means something on that host actively rejected the port.

Timeout vs refused vs no route

MessageWhat it means
Connection timed outNo reply to TCP connect. Packets filtered or host unreachable/silent.
Connection refusedHost reachable, but nothing accepted the port (sshd down or wrong port).
No route to host / Network is unreachableRouting or interface problem before you even reach the server.
Permission denied (publickey)TCP and SSH worked; authentication failed. Different guide.

Check the path first

# Linux / macOS / WSL
nc -vz example.com 22
# or: timeout 5 bash -c 'echo >/dev/tcp/example.com/22' && echo open

# Windows PowerShell
Test-NetConnection example.com -Port 22
# TcpTestSucceeded : False + long wait ≈ timeout / filter
# TcpTestSucceeded : False quickly with connection refused ≈ nothing listening

Also confirm DNS and address: dig +short HOST / Resolve-DnsName HOST, and that you are using the public IP your cloud console shows, not an old elastic IP or a private VPC address from outside the VPC.

Usual causes of a timeout

Once the port answers

ssh -v user@host              # see where it hangs
ssh -J bastion user@internal  # ProxyJump through a reachable bastion
ssh -o ConnectTimeout=5 user@host

Verbose mode shows DNS, the TCP connect, then the key exchange. If it hangs before “Remote protocol version”, you are still in network land. After you get a publickey or password prompt, use the Permission denied (publickey) guide.

Localhost cousins

Talking to a process on your own machine is a different class of error: localhost refused to connect and ECONNREFUSED ::1 mean nothing is listening on that local port (or you hit IPv6 vs IPv4), not that a remote firewall timed out.

Related

ssh Connection refused port 22 · TCP works but keys fail: Permission denied (publickey). Key file permissions too open: SSH key permissions are too open. App on your laptop not listening: localhost refused to connect. Host key suddenly differs: REMOTE HOST IDENTIFICATION HAS CHANGED. Browser says the name itself is unknown: ERR_NAME_NOT_RESOLVED.

Questions

What does ssh Connection timed out mean?

Your client got no TCP reply on that host and port. Typical causes are a cloud security group, host firewall, wrong IP, a machine that is powered off, or a network that blocks outbound port 22.

How is Connection refused different from timed out?

Refused means the host answered and actively rejected the port (sshd not listening or wrong port). Timed out means silence: usually filtering or unreachability.

How do I test if port 22 is open?

Use nc -vz host 22 on Linux/macOS, or Test-NetConnection host -Port 22 in PowerShell. A quick refuse vs a long hang tells refused from timeout.

Can I use another port if 22 is blocked?

Yes, if the server listens there: ssh -p 443 user@host. Some networks block 22 but allow 443. A VPN or ProxyJump through a bastion also works.

Published .

Try it

Related guides

Newest guides