← Back to Error Index
root@linuxfix:~/ssh_connection_refused$
ssh connection refused
SSH connection refused by remote host

Solutions

Prerequisites: Start by updating your system to resolve common issues and ensure the solutions provided below are compatible with your current environment.
check_latest_version && sudo apt update && sudo apt upgrade -y
Check SSH service

Verify SSH is running:

sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh
Test connectivity

Check network and port:

telnet hostname 22
nmap -p 22 hostname
ssh -v user@hostname
Check firewall

Allow SSH through firewall:

sudo ufw allow ssh
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

What is ssh connection refused?

SSH daemon is not running, firewall blocking, or wrong port/credentials.

Common scenarios: Service not running, firewall rules, wrong port, authentication failures.

Common Causes

  • SSH service stopped
  • Firewall blocking port 22
  • Wrong SSH port
  • Authentication failure
  • Too many login attempts

Debugging Tips

ss -tlnp | grep :22
journalctl -u ssh
cat /etc/ssh/sshd_config

Prevention

  • Monitor SSH service
  • Configure fail2ban
  • Use key authentication
  • Change default port
ssh remote connection security