When connecting to an SSH server, the connection hangs and then fails:
$ ssh user@server.example.com
banner exchange: Connection to 192.168.1.100 port 22: Connection timed outOr you might see:
ssh_exchange_identification: read: Connection timed outThis error occurs during the initial SSH protocol handshake. The server should immediately send a banner like SSH-2.0-OpenSSH_8.9p1, but it's not responding in time.
Understand the Banner Exchange
When you connect, the server must immediately send its protocol identification:
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3This happens before any authentication. If the server takes too long, the client times out.
Check Network Connectivity
First, verify basic connectivity:
ping -c 3 server.example.comIf ping fails or is very slow, you have a network issue.
Test if the port is reachable:
nc -zv server.example.com 22 -w 5If this times out, the server might not be reachable or a firewall is blocking.
Test Banner Response
Use telnet or nc to see if the server sends its banner:
nc server.example.com 22Or:
timeout 5 telnet server.example.com 22A healthy server responds immediately:
SSH-2.0-OpenSSH_8.9p1If there's a long delay before this appears, the server has performance issues.
Check Server-Side DNS Resolution
SSHD might be trying to resolve your client's hostname. On the server, disable DNS lookups:
sudo grep UseDNS /etc/ssh/sshd_configIf set to yes or missing (defaults to yes):
sudo sed -i 's/^UseDNS.*/UseDNS no/' /etc/ssh/sshd_configOr add it:
echo "UseDNS no" | sudo tee -a /etc/ssh/sshd_config
sudo systemctl restart sshdThis prevents the server from doing reverse DNS lookup on your IP, which can cause delays if DNS is slow.
Check Server GSSAPI
GSSAPI authentication can cause banner delays:
sudo grep GSSAPIAuthentication /etc/ssh/sshd_configIf enabled and you're not using GSSAPI:
sudo sed -i 's/^GSSAPIAuthentication.*/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart sshdAlso check:
sudo grep GSSAPICleanupCredentials /etc/ssh/sshd_configIncrease Client Timeout
If the server is legitimately slow, increase your client timeout:
ssh -o ConnectTimeout=30 user@server.example.comIn ~/.ssh/config:
Host slow-server.example.com
ConnectTimeout 30Default timeout is typically around 10 seconds.
Check Server Load
On the server, check if it's overloaded:
top -bn1 | head -20Or:
uptimeHigh load can delay SSHD's response to new connections.
Check SSHD process count:
ps aux | grep sshd | wc -lToo many SSHD processes might indicate MaxStartups throttling.
Check MaxStartups Configuration
SSHD throttles connections when many are arriving:
sudo grep MaxStartups /etc/ssh/sshd_configDefault is 10:30:100. If connections exceed 10, new ones are dropped with increasing probability.
Increase it:
echo "MaxStartups 50:30:100" | sudo tee -a /etc/ssh/sshd_config
sudo systemctl restart sshdCheck Server Firewall
Server-side firewalls can rate-limit connections:
sudo iptables -L INPUT -v -nLook for rules with recent module or rate limiting:
DROP tcp -- anywhere anywhere tcp dpt:ssh recent: UPDATE seconds: 60 hit_count: 4 name: ssh side: sourceTemporarily disable to test:
sudo iptables -FFor firewalld:
sudo firewall-cmd --list-allCheck MTU Issues
Large packets might be dropped, causing delays during key exchange:
# On client
ip link show eth0 | grep mtuTest with smaller MTU:
ssh -o "MTU=1200" user@server.example.comCheck for Proxy or Load Balancer
If there's a proxy between you and the server, it might be slow:
# Test direct connection if possible
ssh user@192.168.1.100 # Direct IP, bypass DNSLoad balancers can also cause delays if misconfigured for SSH.
Check SSHD Logs
On the server, watch SSHD activity:
sudo journalctl -u sshd -fConnect and look for:
Apr 3 10:15:22 server sshd[12345]: Connection from 192.168.1.50 port 22 on 192.168.1.100 port 22
Apr 3 10:15:25 server sshd[12345]: Did not receive identification string from 192.168.1.50 port 22The "Did not receive identification string" means the client didn't respond quickly enough.
Check Client-Side Issues
Your client might have problems. Check SSH client config:
cat ~/.ssh/config | grep -i timeoutCheck for slow DNS on your side:
time nslookup server.example.comIf DNS takes seconds, add to /etc/hosts:
echo "192.168.1.100 server.example.com" | sudo tee -a /etc/hostsUse IP Instead of Hostname
Bypass DNS entirely:
ssh user@192.168.1.100Check SSHD Banner Configuration
If a custom banner is configured:
sudo grep Banner /etc/ssh/sshd_configIf Banner points to a slow filesystem or large file, it could cause delays. Remove it:
sudo sed -i 's/^Banner/#Banner/' /etc/ssh/sshd_config
sudo systemctl restart sshdCheck TCP Wrappers
TCP wrappers can cause delays during connection:
cat /etc/hosts.allow
cat /etc/hosts.denyComplex rules or DNS checks in these files can slow the initial handshake.
Test from Different Network
Connect from a different location to rule out your network:
ssh user@server.example.comIf it works from elsewhere, your network is the issue.
Resolution Checklist
- 1.Test network connectivity:
pingandnc -zv - 2.Check banner response:
nc server 22 - 3.Disable DNS lookups:
UseDNS no - 4.Disable GSSAPI:
GSSAPIAuthentication no - 5.Increase client timeout:
ConnectTimeout 30 - 6.Check server load and MaxStartups
- 7.Check firewall rate limiting
- 8.Use IP instead of hostname
- 9.Check MTU if network is unstable
Banner exchange timeouts are usually caused by slow DNS resolution or overloaded servers. Start by testing the raw banner response and disabling DNS lookups on the server.