How to fix ssh: connect to host hostname port 22: Connection timed out in SSH

SSHINTERMEDIATEHIGHUpdated Jan 4, 2026· 175 views

The SSH client cannot reach the remote server on port 22 within the timeout period. This typically indicates a firewall blocking the connection, the SSH service not running, or network connectivity problems between your machine and the host.

Quick fix

Fixes ssh: connect to host hostname port 22: Connection timed out

ping -c 4 hostname.example.com
# or
ping -c 4 192.168.1.100
  1. Verify basic network connectivity to the server
  2. Test if port 22 is open on the remote server
  3. On the server: Verify SSH daemon is running
  4. Check host firewall rules on the server
ssh — error
ping -c 4 hostname.example.com
# or
ping -c 4 192.168.1.100
ssh: connect to host hostname port 22: Connection timed out

What this error means

This error occurs when SSH attempts to establish a connection to a remote server but fails to receive a response within the default timeout (usually 30 seconds). The 'Connection timed out' message means the network request was sent but never received a reply, which differs from 'Connection refused' (where the server actively rejects the connection). This can happen at several network layers: your firewall, the server's firewall, intermediate network routers, cloud security groups, or ISP-level blocking.

Typical symptoms

  • SSH commands hang for 30+ seconds before timing out
  • Works with some servers but not others
  • Works from some networks but not others (office vs home)
  • Works with IP address but not with hostname
  • Works with a different SSH port on the same server

Common causes

  1. Host firewall (ufw, firewalld, iptables) is blocking port 22
  2. Cloud provider security group (AWS, Azure, GCP) doesn't allow SSH
  3. Network firewall or corporate proxy blocking port 22
  4. SSH daemon (sshd) is not running on the remote server
  5. Wrong IP address or hostname - server doesn't exist at that address
  6. Server is offline or unreachable
  7. ISP or network provider blocking port 22
  8. SSH configured to listen on a non-standard port (not 22)
  9. Network routing issues or misconfigured DNS

How to fix "ssh: connect to host hostname port 22: Connection timed out"

1Verify basic network connectivity to the server

First, check if you can reach the server at all using ping or a connectivity test. If the server is completely unreachable, networking issues are the root cause.

bash
ping -c 4 hostname.example.com
# or
ping -c 4 192.168.1.100

If ping fails, the server is offline or your network can't reach it. If ping succeeds, proceed to the next step.

2Test if port 22 is open on the remote server

Use telnet or netcat to test if port 22 is accepting connections. This tells you if the server is listening on port 22.

bash
# Using telnet (may not be installed)
telnet hostname.example.com 22

# Using netcat (better, more reliable)
nc -zv hostname.example.com 22

# Using timeout to prevent hanging
timeout 5 telnet hostname.example.com 22

If you get 'Connection refused', the port is closed. If you get 'Connection timed out', the firewall is blocking it. If you get a response with SSH version info, port 22 is open and listening.

3On the server: Verify SSH daemon is running

Connect to the server using a different method (console, VNC, KVM) and check that sshd is running:

bash
# Check SSH daemon status
sudo systemctl status sshd

# If not running, start it
sudo systemctl start sshd

# Enable it to start on boot
sudo systemctl enable sshd

On older systems without systemd:

bash
sudo service ssh status
sudo service ssh start

Verify SSH is listening on port 22:

bash
sudo ss -tlnp | grep ssh
# or
sudo netstat -tlnp | grep ssh
4Check host firewall rules on the server

If sshd is running but port 22 is blocked, check the server's firewall:

bash
# For UFW (Ubuntu/Debian)
sudo ufw status
sudo ufw allow 22/tcp

# For firewalld (CentOS/RHEL)
sudo firewall-cmd --list-all
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

# For iptables (check rules)
sudo iptables -L -n | grep 22

# If iptables is blocking, allow SSH
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables-save  # Make changes persistent
5Check cloud provider security groups or network ACLs

If your server is on a cloud provider, ensure the security group allows inbound SSH:

AWS:
- Security Group > Inbound Rules > Add rule
- Protocol: TCP, Port: 22, Source: Your IP or 0.0.0.0/0 (less secure)

Azure:
- Network security group > Inbound security rules
- Add rule allowing TCP port 22 from your IP

GCP:
- VPC network > Firewall rules
- Create rule allowing tcp:22 traffic

Also check Network ACLs (if used) - they can block traffic before security groups.

6Verify the correct port is being used

If the server is configured to use a non-standard SSH port, you must specify it in your command:

bash
# Default port 22
ssh user@hostname.com

# Custom port (e.g., 2222)
ssh -p 2222 user@hostname.com

Check the server's SSH configuration to find the actual port:

bash
grep '^Port' /etc/ssh/sshd_config

Default is 22 if this line is commented out.

7Test with verbose output to diagnose the issue

Use SSH's verbose flags to see exactly where the connection is failing:

bash
# Single verbose
ssh -v user@hostname.com

# Double verbose (more details)
ssh -vv user@hostname.com

# Triple verbose (maximum details)
ssh -vvv user@hostname.com

Look for the line where it gets stuck - usually something like:
- 'Trying X.X.X.X...' means it's trying to connect
- No response after this = firewall blocking the connection
- 'Timeout' message = connection timed out (firewall)
- 'Connection refused' = port is closed on server

8Check ISP or network provider blocking

Some ISPs or corporate networks block port 22 for security. Test this:

bash
# Try using a port known to be open (like 443 for HTTPS)
# Ask your server admin to listen on this alternate port
ssh -p 443 user@hostname.com

# Or test with a public SSH server (if allowed)
ssh -p 22 user@github.com  # GitHub allows SSH

If alternate ports work but 22 doesn't, your network provider may be blocking port 22. Solutions:
- Use a VPN to bypass the block
- Ask your IT/ISP to unblock port 22
- Configure SSH on an alternate port (443, 8022, etc.) with server admin help

9Increase SSH timeout for slow networks

If connections work but are slow, increase the client-side timeout:

bash
# Increase timeout to 30 seconds (default is ~20)
ssh -o ConnectTimeout=30 user@hostname.com

Or add to your ~/.ssh/config file:

bash
Host *
    ConnectTimeout 30
    ServerAliveInterval 60
    ServerAliveCountMax 3

These settings prevent idle connections from timing out and increase the initial connection timeout for slow networks.

Advanced notes

Root cause flow chart: Start with ping to verify network reach. If ping works, use nc -zv to test port 22. If port 22 is closed, check sshd is running. If sshd is running, check firewall rules. If testing from multiple networks and it fails everywhere, the issue is server-side (firewall or sshd). If it fails from some networks (office/VPN) but works from home, the issue is likely ISP/corporate firewall blocking port 22.

Debugging tips: The verbose output -vvv is invaluable - it shows exactly where the connection gets stuck. Pay attention to the IP address SSH is trying to connect to (sometimes DNS resolution is the issue). If you see 'Trying X.X.X.X...' with no response, a firewall between you and the server is blocking traffic. If you see 'connect to host port 22: Connection refused', the server is reachable but sshd isn't listening.

Alternative ports: Some networks block port 22 but allow others. Common alternatives: 443 (HTTPS), 8022, 2222. Require server admin to configure sshd on the alternate port in /etc/ssh/sshd_config.

Frequently asked questions

What does "ssh: connect to host hostname port 22: Connection timed out" mean?
This error occurs when SSH attempts to establish a connection to a remote server but fails to receive a response within the default timeout (usually 30 seconds). The 'Connection timed out' message means the network request was sent but never received a reply, which differs from 'Connection refused' (where the server actively rejects the connection). This can happen at several network layers: your firewall, the server's firewall, intermediate network routers, cloud security groups, or ISP-level blocking.
How do I fix "ssh: connect to host hostname port 22: Connection timed out"?
The SSH client cannot reach the remote server on port 22 within the timeout period. This typically indicates a firewall blocking the connection, the SSH service not running, or network connectivity problems between your machine and the host.
What causes "ssh: connect to host hostname port 22: Connection timed out"?
Host firewall (ufw, firewalld, iptables) is blocking port 22 Cloud provider security group (AWS, Azure, GCP) doesn't allow SSH Network firewall or corporate proxy blocking port 22
Is the "ssh: connect to host hostname port 22: Connection timed out" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading