No articles found
Try different keywords or browse our categories
Fix: SSH connection timed out error
Complete guide to fix 'SSH connection timed out' error. Learn how to resolve SSH connection timeout issues with remote servers.
The ‘SSH connection timed out’ error occurs when the SSH client cannot establish a connection to the remote server within the default timeout period, typically due to network issues, firewall restrictions, or server unavailability.
How the Error Happens
This error typically occurs when:
- Network connectivity issues between client and server
- Firewall blocking SSH traffic on port 22
- Remote server is down or overloaded
- Network latency is too high
- SSH daemon not running on remote server
- ISP or corporate firewall restrictions
Solution 1: Test Network Connectivity
# ✅ Test basic network connectivity
ping remote-server.com
# ✅ Test specific port connectivity
telnet remote-server.com 22
# OR using nc (netcat)
nc -zv remote-server.com 22
# ✅ Test SSH port specifically
nmap -p 22 remote-server.com
# ✅ Check if port 22 is open
telnet remote-server.com 22
# If connection is refused, port might be blocked
# ✅ Trace network path
traceroute remote-server.com
# OR on Windows
tracert remote-server.com
Solution 2: Increase SSH Timeout Values
# ✅ Connect with increased timeout
ssh -o ConnectTimeout=60 user@remote-server.com
# ✅ Set connection attempts
ssh -o ConnectionAttempts=5 -o ConnectTimeout=30 user@remote-server.com
# ✅ Use multiple options
ssh -o ConnectTimeout=60 -o ConnectionAttempts=3 -o ServerAliveInterval=30 user@remote-server.com
# ✅ Edit SSH config for persistent settings
nano ~/.ssh/config
# ✅ Add timeout configuration
Host remote-server.com
ConnectTimeout 60
ConnectionAttempts 5
ServerAliveInterval 30
ServerAliveCountMax 3
Solution 3: Check SSH Service on Remote Server
# ✅ If you have console access to the remote server, check SSH service
# On the remote server:
sudo systemctl status ssh
# OR
sudo systemctl status sshd
# ✅ Start SSH service if not running
sudo systemctl start ssh
# OR
sudo systemctl start sshd
# ✅ Enable SSH service to start on boot
sudo systemctl enable ssh
# ✅ Check if SSH is listening on the correct port
sudo netstat -tlnp | grep :22
# OR
sudo ss -tlnp | grep :22
# ✅ Check SSH configuration
sudo nano /etc/ssh/sshd_config
# Ensure Port 22 is uncommented and correct
# Port 22
Solution 4: Configure Firewall Settings
# ✅ Check firewall status on remote server
sudo ufw status
# OR
sudo iptables -L
# ✅ Allow SSH through firewall
sudo ufw allow ssh
# OR
sudo ufw allow 22/tcp
# ✅ On CentOS/RHEL
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
# ✅ Check local firewall (if applicable)
# On Windows
netsh advfirewall firewall show rule name=all | findstr SSH
# On macOS
sudo pfctl -sr
Solution 5: Use Alternative SSH Ports
# ✅ If SSH is running on a non-standard port
ssh -p 2222 user@remote-server.com
# ✅ Configure SSH config for custom port
nano ~/.ssh/config
# ✅ Add custom port configuration
Host remote-server.com
Port 2222
ConnectTimeout 60
# ✅ Check if SSH is running on alternative port
nmap -p 22,2222,8022 remote-server.com
# ✅ Configure SSH daemon for multiple ports
# Edit /etc/ssh/sshd_config on remote server
Port 22
Port 2222
Solution 6: Use SSH Through Proxy or Jump Host
# ✅ Use a jump host if direct connection fails
ssh -J user@jump-host.com user@remote-server.com
# ✅ Configure SSH config for jump host
nano ~/.ssh/config
# ✅ Add jump host configuration
Host jump-host
HostName jump.example.com
User jumpuser
Host remote-server
HostName remote-server.com
User remoteuser
ProxyJump jump-host
ConnectTimeout 60
# ✅ Use SOCKS proxy if available
ssh -D 1080 user@accessible-server.com
# Then configure your SSH client to use the SOCKS proxy
Solution 7: Optimize SSH Configuration
# ✅ Optimize SSH client configuration
nano ~/.ssh/config
# ✅ Add optimized settings
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
TCPKeepAlive yes
ConnectTimeout 30
ConnectionAttempts 3
Host remote-server.com
ConnectTimeout 120
ConnectionAttempts 5
Compression yes
Cipher aes128-ctr
# ✅ Use compression for slow connections
ssh -o Compression=yes -o Cipher=aes128-ctr user@remote-server.com
# ✅ Use different cipher if default fails
ssh -o Ciphers=aes128-ctr,aes192-ctr,aes256-ctr user@remote-server.com
Solution 8: Check DNS Resolution
# ✅ Test DNS resolution
nslookup remote-server.com
# OR
dig remote-server.com
# ✅ Try connecting with IP address directly
ssh user@192.168.1.100 # Replace with actual IP
# ✅ Add entry to hosts file if DNS is problematic
# On Linux/Mac: sudo nano /etc/hosts
# On Windows: C:\Windows\System32\drivers\etc\hosts
# Add: IP_ADDRESS remote-server.com
# ✅ Flush DNS cache if needed
sudo dscacheutil -flushcache # macOS
sudo systemd-resolve --flush-caches # Linux
ipconfig /flushdns # Windows
Solution 9: Corporate Network Solutions
# ✅ Check if behind corporate proxy
# Configure proxy in SSH config
nano ~/.ssh/config
# ✅ Use proxy command if needed
Host remote-server.com
ProxyCommand nc -X connect -x proxy.company.com:8080 %h %p
ConnectTimeout 60
# ✅ Use VPN if corporate network blocks SSH
# Connect to VPN first, then SSH
openvpn --config company-vpn.ovpn
# Then connect via SSH
ssh user@remote-server.com
Prevention Tips
- Monitor connectivity: Regularly test SSH connections
- Use SSH config: Configure optimal timeout values
- Maintain servers: Keep SSH services running and updated
- Check firewalls: Ensure SSH ports are accessible
- Use monitoring: Set up alerts for server downtime
- Have backups: Maintain alternative access methods
- Document networks: Keep network diagrams updated
- Test regularly: Periodically verify connection paths
When to Contact Support
Contact your hosting provider or network administrator when:
- Following all troubleshooting steps still results in timeout errors
- Suspected infrastructure issues on their side
- Need to investigate server-side network configurations
- Encountering ISP-specific network restrictions
- Experiencing account-related access problems
Related Articles
Fix: Permission denied (publickey) error
Complete guide to fix 'Permission denied (publickey)' error. Learn how to resolve SSH key authentication issues with Git and remote servers.
Fix: 502 Bad Gateway on PHP sites error and fix
Quick fix for 502 Bad Gateway error on PHP sites. Learn how to resolve server gateway issues and improve PHP application stability.
Fix: Allowed memory size exhausted in WordPress error - Quick Solution
Quick fix for 'Allowed memory size exhausted' error in WordPress. Learn how to increase PHP memory limit and optimize WordPress performance.