Attempting to connect to a remote server, cloud VPS, or headless Raspberry Pi via Secure Shell only to have the terminal hang for several minutes before terminating with ssh: connect to host [hostname] port 22: Connection timed out blocks remote management. In computer networking, an SSH connection timeout indicates that your client machine dispatched TCP SYN handshake packets toward destination port 22, but received no response whatsoever—neither a TCP SYN-ACK acknowledging the packet nor a TCP RST rejecting it. The packets were silently dropped along the network path. This behavior typically points to cloud firewall security group rules (such as AWS Security Groups, Google Cloud VPC firewalls, or DigitalOcean Cloud Firewalls), local router NAT forwarding misconfigurations, or network routing blackholes. This guide explains how to trace dropped packets and resolve SSH connection timeouts.
Distinguishing “Connection Timed Out” from “Connection Refused”
Understanding the exact failure mode is critical for rapid network troubleshooting:
- Connection Timed Out: Packets are discarded into a blackhole without an answer. The server never received the packet, or an upstream firewall (AWS, Azure, router) intercepted and silently dropped it.
- Connection Refused: Packets successfully reached the target operating system, but the host actively replied with a TCP RST packet because no SSH daemon was listening on that port.
Common Causes of SSH Connection Timeouts
- Cloud Provider Security Groups: AWS EC2 Security Groups, GCP Firewall Rules, or Azure Network Security Groups (NSGs) lacking an inbound rule allowing TCP traffic on port 22 from your current public IP.
- Dynamic Client Public IP Changes: Your residential broadband ISP dynamically reassigned your external IP address, invalidating IP-restricted firewall rules.
- Host-Based DROP Rules in iptables / UFW: The remote server’s software firewall configured with a default
DROPpolicy for unmatched incoming packets. - ISP / Corporate Network Port 22 Egress Filtering: Coffee shops, hotels, corporate office intranets, or university Wi-Fi networks blocking outbound connections on standard port 22.
- Server Power State or Network Failure: The remote machine is powered off, stuck in kernel panic, or disconnected from the physical gateway.
Method 1: Check and Update Cloud Firewall Security Groups
Most cloud virtual machines default to blocking all incoming traffic unless explicitly permitted in the management console.
- Log into your cloud hosting provider dashboard (AWS Management Console, DigitalOcean, Linode, or Hetzner).
- Locate the Firewall or Security Group attached to your server instance.
- Inspect the Inbound Rules (Ingress):
- Ensure there is an active rule with Type: SSH, Protocol: TCP, and Port Range: 22.
- Check the Source IP. If the rule is restricted to a specific IP address (e.g.
203.0.113.45/32), verify your current public IP by visiting whatismyipaddress.com. If your ISP changed your IP, update the rule.
- Save changes. Cloud firewall rules take effect within seconds.
Method 2: Test Outbound Port 22 Connectivity with Netcat or Curl
Verify whether your local internet service provider or router is blocking outgoing connections on port 22.
- In your local terminal, test TCP connectivity to a known public SSH endpoint:
nc -zv portquiz.net 22 - If the output returns “Connection to portquiz.net 22 port [tcp/ssh] succeeded!”, your local network permits outbound port 22 traffic.
- If the command hangs and times out, your local Wi-Fi router or ISP is blocking outbound port 22:
- Connect your laptop to a mobile 4G/5G phone hotspot to bypass network filtering.
- Configure your server to listen on a non-standard port (such as 443 or 2222) which is rarely blocked by public Wi-Fi networks.
Method 3: Run Traceroute and Ping Diagnostics
Isolate where along the network path packets are being dropped.
- Test basic ICMP ping reachability:
(Note: Many cloud servers deliberately disable ICMP ping; lack of ping response does not guarantee the server is down).ping -c 4 server_ip - Trace the network path to identify intermediate hop failures:
(Usingtraceroute -p 22 -T server_ip-Tinstructs traceroute to utilize TCP SYN packets rather than UDP or ICMP). - Observe where the traceroute asterisks (
* * *) begin. If packets reach the final hop before dropping, the issue resides on the host or cloud hypervisor firewall.
Method 4: Connect via Cloud Web VNC / Serial Console
If network SSH access remains blocked, log in through your cloud provider’s out-of-band console to inspect local firewalls.
- In your cloud dashboard (e.g. AWS EC2 Console > EC2 Serial Console or DigitalOcean > Recovery Console), launch the web-based shell.
- Log in with your root credentials.
- Inspect local UFW firewall status:
sudo ufw status verbose - If port 22 is missing, permit it:
sudo ufw allow 22/tcp sudo ufw reload - Verify that the SSH daemon is actively running:
sudo systemctl status sshd
SSH Timeout vs Refusal Diagnostic Matrix
| Reported Output | Network Behavior | Probable Cause |
|---|---|---|
Connection timed out |
Packets silently dropped (no reply) | Cloud security group blocking IP or local router firewall dropping port 22 |
Connection refused |
Immediate TCP RST packet received | Target server reached, but sshd daemon stopped or listening on different port |
No route to host |
ICMP Host Unreachable received | Network routing failure or gateway IP misconfiguration |
Operation timed out (macOS) |
Local client socket timeout | VPN tunnel broken or routing table conflict |
Frequently Asked Questions
How can I run SSH on port 443 to bypass restrictive firewalls?
On your server, open /etc/ssh/sshd_config, add Port 443 on a new line below Port 22, adjust your firewall to allow port 443, and restart SSH (sudo systemctl restart ssh). You can then connect via ssh -p 443 user@server_ip.
Can Fail2ban cause SSH connection timeouts?
Yes. If you enter incorrect passwords repeatedly, Fail2ban may add an iptables DROP rule targeting your public IP address. Connect through your cloud console and run sudo fail2ban-client unban [your_ip] to restore access.