debugbashMajorpending
Debug: SSH connection troubleshooting
Viewed 0 times
sshconnection refusedpermission deniedpublickeyssh configverbose
Error Messages
Problem
SSH connection fails, hangs, or disconnects unexpectedly.
Solution
Systematic SSH debugging:
# 1. Verbose output (most useful)
ssh -vvv user@host 2>&1 | head -100
# Look for: where it gets stuck
# - DNS resolution
# - TCP connection
# - Key exchange
# - Authentication
# 2. Check basic connectivity
ping host # Is host reachable?
nc -zv host 22 # Is SSH port open?
nmap -p 22 host # Port scan
# 3. Common issues:
# Permission denied (publickey)
ssh -i ~/.ssh/mykey user@host # Specify key explicitly
ls -la ~/.ssh/ # Check permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/authorized_keys # On server
# Connection refused
# -> sshd not running on server
# -> Wrong port (try ssh -p 2222 user@host)
# -> Firewall blocking
# Connection timed out
# -> Host unreachable or firewall dropping packets
# -> Try: ssh -o ConnectTimeout=10 user@host
# Connection drops after idle
# Add to ~/.ssh/config:
# Host *
# ServerAliveInterval 60
# ServerAliveCountMax 3
# Too many authentication failures
# -> ssh-agent has too many keys loaded
ssh-add -l # List loaded keys
ssh-add -D # Remove all
ssh-add ~/.ssh/specific_key # Add only needed key
# Or: ssh -o IdentitiesOnly=yes -i key user@host
# 4. Check server-side
sudo tail -f /var/log/auth.log # Debian/Ubuntu
sudo journalctl -u sshd -f # systemd
sudo sshd -T # Test configWhy
SSH failures happen at multiple layers (DNS, TCP, crypto, auth). The -vvv flag reveals exactly which stage fails, making targeted debugging possible.
Context
Debugging SSH connections to remote servers
Revisions (0)
No revisions yet.