Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SSH Connection Timed Out: How to Fix Port 22

· 5 min read · Home Tech

In this article
  1. What Causes the Timeout
  2. Step-by-Step Diagnosis
  3. Firewall and Security Group Checks
  4. Common Misconception: "Port 22 is blocked"
  5. When the Server is Behind NAT or a Router
  6. Alternatives to Port 22
  7. Frequently Asked Questions

The "ssh: connect to host ... port 22: Operation timed out" error means your client could not establish a TCP connection to the server's SSH port within the timeout period. The fix usually involves checking the server's IP address, firewall rules, SSH service status, and network routing — in that order.

What Causes the Timeout

A timeout is different from a "connection refused" error. A refusal means the server is reachable but nothing is listening on port 22. A timeout means your packets are being dropped or ignored entirely. Common causes include:

  • The server is offline or the IP address has changed.
  • A firewall (local, cloud security group, or ISP) is blocking outbound or inbound port 22.
  • The SSH service (sshd) is not running or is listening on a different port.
  • Network issues like a wrong subnet mask, VPN misconfiguration, or a dead router.
  • The server is overloaded or the SSH daemon is unresponsive.

Step-by-Step Diagnosis

  1. Verify the server is up: Ping the host. If ping fails, the server may be offline, or ICMP is blocked. If ping works but SSH times out, the issue is likely port-specific.
  2. Check the port is open: Use a tool like nc -zv <host> 22 or telnet <host> 22. If the connection hangs, the port is filtered or blocked.
  3. Test from another network: Try SSH from a different internet connection (e.g., phone hotspot). If it works, your local network or ISP is blocking the port.
  4. Check the SSH service: On the server, run sudo systemctl status sshd (or ssh on some distros). Ensure it is active and listening with sudo ss -tlnp | grep :22.
  5. Inspect firewall rules: On the server, check sudo iptables -L -n or sudo ufw status. For cloud servers, review the security group inbound rules — port 22 must be allowed from your IP.
  6. Check SSH config: The server may be configured to listen on a non-standard port. Look at /etc/ssh/sshd_config for the Port directive.

Firewall and Security Group Checks

Firewalls are the most common cause of timeouts. On the server side, ensure that port 22 is open for incoming connections. If you use a cloud provider (AWS, Azure, GCP), the security group or network ACL must allow inbound TCP on port 22 from your IP address. Many cloud providers default to blocking all inbound traffic except specific ports. On the client side, some corporate networks block outbound SSH. You can test by temporarily disabling your local firewall (if you have admin rights) or using a different network.

Common Misconception: "Port 22 is blocked"

Many users assume that a timeout always means the port is blocked by a firewall. However, a timeout can also occur if the server's IP is incorrect, the server is down, or the network path is broken. Always start with a ping and a traceroute to isolate the problem. For example, if you can ping the server but not connect to port 22, the issue is likely a firewall or the SSH service. If you cannot ping, the problem is more fundamental.

When the Server is Behind NAT or a Router

If the server is on a private network behind a router, you must set up port forwarding. The router must forward incoming TCP traffic on port 22 to the server's private IP address. Also, the server's local firewall must allow connections from the router's LAN IP. If the public IP is dynamic, consider using a dynamic DNS service. A common mistake is forgetting to update the port forward when the server's private IP changes.

Alternatives to Port 22

If port 22 is blocked by your ISP or network, you can change the SSH port on the server to something else (e.g., 2222). Edit /etc/ssh/sshd_config and change the Port line, then restart sshd. Remember to update your firewall rules accordingly. Alternatively, you can use a VPN or SSH over HTTPS (port 443) using tools like sslh or ssh over TLS. Another option is to use a web-based SSH client like shellinabox or a cloud-based SSH gateway.

Frequently Asked Questions

Why does SSH time out but ping works?

This usually means the server is reachable at the network layer, but the SSH port is filtered or the SSH service is not listening. Check the firewall rules on the server and the security group if it's a cloud instance. Also, verify that sshd is running and listening on the expected port.

How do I change the SSH port?

Edit the /etc/ssh/sshd_config file on the server, find the line that says #Port 22, uncomment it and change the number to your desired port (e.g., Port 2222). Save the file and restart the SSH service with sudo systemctl restart sshd. Then connect using ssh -p 2222 user@host. Make sure your firewall allows the new port.

What does "Connection timed out" mean vs "Connection refused"?

A timeout means the network packet was sent but no response was received — the server may be down, the port is blocked, or the route is broken. A refusal means the server is reachable but no application is listening on that port. Refusal is often faster and indicates the SSH service is not running or the port is wrong.

Can a VPN cause SSH timeouts?

Yes. If you are connected to a VPN, traffic may be routed through a tunnel that blocks or misroutes port 22. Try disconnecting the VPN and connecting again. If it works, the VPN's network configuration or firewall is the issue.

Why does SSH work locally but not from the internet?

This typically points to a port forwarding problem or a firewall on the router. Ensure that port 22 is forwarded to the server's private IP. Also, check that the server's firewall allows connections from the internet (not just the LAN).

How can I test if port 22 is open from my computer?

Use the nc (netcat) command: nc -zv <host> 22. If it returns "succeeded", the port is open. If it hangs or says "timed out", the port is blocked or the host is unreachable. On Windows, you can use Test-NetConnection <host> -Port 22 in PowerShell.