SSH connection refused means you cannot access your server remotely. This is one of the most critical issues to resolve — here is how to regain access systematically.
Diagnosing the Error
# From your local machine
ssh -v user@yourserver
# -v shows verbose connection details
# Common errors:
# "Connection refused" — SSH not running OR firewall blocking
# "Connection timed out" — firewall dropping packets
# "Permission denied" — wrong key or password
# "Host key verification failed" — server fingerprint changed
Step 1 — Check via Cloud Console First
If you cannot SSH, use your hosting provider's web console:
- Hetzner → Server → Console
- DigitalOcean → Droplet → Console
- AWS → EC2 → Connect → Session Manager
- CloudPanel → SSH Terminal
Step 2 — Fix SSH Service Not Running
# Via web console
sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh
Step 3 — Fix Firewall Blocking SSH
# UFW
sudo ufw status
sudo ufw allow 22/tcp
sudo ufw reload
# iptables
sudo iptables -L INPUT -n | grep 22
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# CSF Firewall
csf -a YOUR_IP "Temporary access"
Step 4 — Fix Wrong SSH Port
# Check what port SSH is listening on
sudo ss -tulpn | grep ssh
sudo grep "^Port" /etc/ssh/sshd_config
# Connect with specific port
ssh -p 2222 user@yourserver
Step 5 — Fix Fail2Ban IP Ban
# Check if your IP is banned
sudo fail2ban-client status sshd
# Unban your IP
sudo fail2ban-client set sshd unbanip YOUR_IP
Step 6 — Fix SSH Key Issues
# Check key permissions (must be 600)
chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh
# Test specific key
ssh -i ~/.ssh/your-key.pem user@server
# Check server authorized_keys
cat ~/.ssh/authorized_keys
Conclusion
SSH lockouts need immediate resolution. Our team provides emergency server access recovery via out-of-band console access.
Comments