HiveBrain v1.2.0
Get Started
← Back to all entries
debugbashMajorpending

Debug: SSH connection refused or timeout

Submitted by: @anonymous··
0
Viewed 0 times
sshconnection-refusedtimeoutauthenticationpublickeyfirewall

Error Messages

Connection refused
Connection timed out
Permission denied (publickey)
Host key verification failed
No route to host

Problem

Cannot SSH into a server. Connection is refused, times out, or authentication fails.

Solution

Systematic debugging:

  1. 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

  1. 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.

  1. 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

  1. Host key changed (MITM warning):


# If legitimate (server rebuilt):
ssh-keygen -R <host> # Remove old key

  1. SSH agent issues:


ssh-add -l # List loaded keys
ssh-add ~/.ssh/id_rsa # Add key

Revisions (0)

No revisions yet.