debugbashMajorpending
Debug: SSH connection refused or timeout
Viewed 0 times
sshconnection-refusedtimeoutauthenticationpublickeyfirewall
Error Messages
Problem
Cannot SSH into a server. Connection is refused, times out, or authentication fails.
Solution
Systematic debugging:
# Check if sshd is running:
systemctl status sshd
# Check if listening on port 22:
ss -tlnp | grep 22
# Firewall blocking?
sudo iptables -L -n | grep 22
sudo ufw status
# Check network connectivity:
ping <host>
# Check if port is reachable:
nc -zv <host> 22 -w 5
# Traceroute:
traceroute <host>
# Security group / firewall on cloud:
# Check AWS SG, GCP firewall rules, etc.
# Verbose SSH for details:
ssh -vvv user@host
# Check key permissions (MUST be restrictive):
chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh/
# Check authorized_keys on server:
cat ~/.ssh/authorized_keys
# Check sshd config:
grep -i 'passwordauth\|pubkeyauth\|permitroot' /etc/ssh/sshd_config
# If legitimate (server rebuilt):
ssh-keygen -R <host> # Remove old key
ssh-add -l # List loaded keys
ssh-add ~/.ssh/id_rsa # Add key
- Connection refused (port 22 not listening):
# Check if sshd is running:
systemctl status sshd
# Check if listening on port 22:
ss -tlnp | grep 22
# Firewall blocking?
sudo iptables -L -n | grep 22
sudo ufw status
- Connection timeout (can't reach host):
# Check network connectivity:
ping <host>
# Check if port is reachable:
nc -zv <host> 22 -w 5
# Traceroute:
traceroute <host>
# Security group / firewall on cloud:
# Check AWS SG, GCP firewall rules, etc.
- Authentication failures:
# Verbose SSH for details:
ssh -vvv user@host
# Check key permissions (MUST be restrictive):
chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh/
# Check authorized_keys on server:
cat ~/.ssh/authorized_keys
# Check sshd config:
grep -i 'passwordauth\|pubkeyauth\|permitroot' /etc/ssh/sshd_config
- Host key changed (MITM warning):
# If legitimate (server rebuilt):
ssh-keygen -R <host> # Remove old key
- SSH agent issues:
ssh-add -l # List loaded keys
ssh-add ~/.ssh/id_rsa # Add key
Revisions (0)
No revisions yet.