Error Codes Wiki

Linux SSH Connection Refused — Port 22

Errornetwork

Overview

SSH 'Connection refused' on port 22 means the SSH server is not running, the port is blocked, or SSH is configured on a different port.

Key Details

  • TCP connection to port 22 is actively refused by the target
  • Different from 'Connection timed out' which means the port is filtered/blocked
  • The SSH daemon (sshd) must be running on the target machine
  • Firewall rules may block port 22 even if sshd is running
  • SSH may be configured on a non-standard port for security

Common Causes

  • SSH server (sshd) not installed or not running
  • Firewall (iptables/nftables/ufw) blocking port 22
  • SSH configured on a non-standard port
  • TCP Wrappers (/etc/hosts.deny) blocking the client IP
  • SELinux policy blocking SSH connections

Steps

  1. 1Check if sshd is running: systemctl status sshd (or ssh on Debian/Ubuntu)
  2. 2Start SSH: sudo systemctl start sshd && sudo systemctl enable sshd
  3. 3Check firewall: sudo ufw status or sudo iptables -L -n | grep 22
  4. 4Allow SSH through firewall: sudo ufw allow 22 or sudo firewall-cmd --add-service=ssh --permanent
  5. 5Check SSH port: grep Port /etc/ssh/sshd_config — connect with ssh -p PORT user@host

Tags

linuxsshconnection-refusedport-22remote

More in Network

Frequently Asked Questions

Refused means the server actively rejected the connection (nothing listening on port 22). Timed out means a firewall silently dropped the packets.