ssh: connect to host example.com port 22: Connection timed out
SSH canβt reach the server within the timeout period.
Why this happens
A connection timeout means the TCP handshake never completed β your packets either never reached the server or the server never responded. This is almost always a network-level issue: a firewall silently dropping packets, the server being offline, or a routing problem between you and the host.
Fix 1: Check if the server is reachable
ping example.com
telnet example.com 22
Fix 2: Check if SSH is running on the server
sudo systemctl status sshd
sudo systemctl start sshd
Fix 3: Firewall blocking port 22
sudo ufw status
sudo ufw allow 22
Fix 4: Wrong port
ssh -p 2222 user@example.com
Fix 5: Cloud provider security group
If using AWS/GCP/Azure, check that the security group allows inbound TCP on port 22 from your IP.
Alternative solutions
Use verbose mode to pinpoint where the connection stalls:
ssh -vvv user@example.com
If your ISP blocks port 22, configure SSH over port 443 in ~/.ssh/config:
Host example.com
Port 443
Prevention
- Add
ServerAliveInterval 60to~/.ssh/configto prevent idle timeouts. - Use a bastion host if connecting from networks that restrict outbound SSH.
Related resources
Related: SSH: Host Key Verification Failed Β· ERR_CONNECTION_REFUSED β How to Fix It