How to fix refused connect from hostname in SSH
The SSH daemon (sshd) is rejecting incoming connections from a specific hostname or IP address. This typically indicates TCP wrapper restrictions, firewall rules, or service misconfiguration preventing client access.
Quick fix
Fixes refused connect from hostname
sudo systemctl status sshd- Check if SSH daemon is actually running
- Check TCP Wrappers configuration (hosts.allow/hosts.deny)
- Verify the connecting IP or hostname
- Check firewall rules (iptables or firewalld)
sudo systemctl status sshdrefused connect from hostname
What this error means
When sshd logs 'refused connect from hostname', it means the SSH server is actively rejecting the connection attempt before authentication occurs. This is different from a timeout or port closure. The refusal usually originates from TCP Wrappers (hosts.allow/hosts.deny files), which act as an additional access control layer on Linux systems. The SSH daemon checks these rules first, and if the connecting IP is explicitly denied or not explicitly allowed, the connection is refused. This message can also indicate that sshd itself encountered an error or is misconfigured.
Typical symptoms
- SSH connection attempts immediately fail with 'Connection refused'
- Client sees 'refused' message in debug output (ssh -vvv)
- Server logs show 'sshd[PID]: refused connect from X.X.X.X' messages
- Issue affects specific clients or subnets, while others can connect
- Connections fail even though port 22 is open and sshd appears to be running
- Problem persists after SSH authentication would have normally occurred
Common causes
- TCP Wrappers (hosts.deny) blocking the connecting IP address or hostname
- TCP Wrappers (hosts.allow) does not explicitly permit the connecting client
- SSH daemon was stopped or not properly started (appears running but rejects all connections)
- Firewall iptables rules or other kernel-level access controls rejecting connections
- SELinux or AppArmor policies preventing sshd from accepting connections
- Invalid or corrupted sshd configuration file preventing proper service initialization
- Fail2Ban or similar intrusion detection system blocking the IP address
How to fix "refused connect from hostname"
First, verify that sshd is properly running and listening:
sudo systemctl status sshdIf the status shows 'active (running)', restart it:
sudo systemctl restart sshdThen immediately test your connection again. Sometimes sshd can appear to be running but has a stale state.
TCP Wrappers is a common cause of 'refused connect' messages. Check both configuration files:
sudo cat /etc/hosts.deny
sudo cat /etc/hosts.allowLook for any lines containing 'sshd' or 'ALL'. If you see sshd: ALL in hosts.deny, that's blocking all SSH connections. Remove or comment out such lines.
To explicitly allow SSH from your client IP, add to /etc/hosts.allow:
sudo echo 'sshd: 192.168.1.100' >> /etc/hosts.allowReplace 192.168.1.100 with your actual client IP address.
Identify what IP address or hostname the client is connecting from. Check the server logs:
sudo tail -f /var/log/auth.logOr on some systems:
sudo tail -f /var/log/secureLook for the 'refused connect from' line. Note the IP address shown. This is the address you need to allow in TCP Wrappers or firewall rules.
Verify that your firewall isn't blocking port 22:
sudo iptables -L -n | grep 22Or for firewalld:
sudo firewall-cmd --list-all | grep sshIf port 22 is blocked, allow it:
With iptables:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTWith firewalld:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reloadCheck your SSH daemon configuration for any explicit restrictions:
sudo cat /etc/ssh/sshd_config | grep -i 'allow\|deny'Look for directives like AllowUsers, DenyUsers, AllowGroups, or DenyGroups. If your user or IP is in a deny list, remove it or add yourself to the allow list.
Also check for Protocol, ListenAddress, or Port misconfigurations. If sshd is not listening on the correct interface or port, connections will be refused.
If you have Fail2Ban installed, it might be blocking your IP:
sudo fail2ban-client status sshdIf your IP is in the banned list, unban it:
sudo fail2ban-client set sshd unbanip 192.168.1.100Replace 192.168.1.100 with your actual IP address.
Once changes are made, test with verbose SSH output to confirm the connection:
ssh -vvv user@hostnameThis will show detailed logs of where the connection is failing. Look for 'refused' messages and use them to identify which component (TCP Wrappers, firewall, sshd config) is causing the rejection.
Advanced notes
TCP Wrappers (libwrap) is a legacy access control mechanism that some systems still use. To check if sshd was compiled with TCP wrapper support, run: ldd /usr/sbin/sshd | grep libwrap. If libwrap is listed, TCP Wrappers rules are active. On modern systems using systemd and SELinux, ensure SELinux booleans like ssh_sysadm_login are set correctly. Some container environments (Docker, Kubernetes) may have network policies that appear as 'refused connect' errors at the sshd level. Additionally, some systems use tcpd directly as a wrapper around sshd in inetd.conf or systemd socket activation, which can also trigger this message. Always check system logs (journalctl, /var/log/auth.log) for the exact sshd error codes for more precise troubleshooting.
Frequently asked questions
- What does "refused connect from hostname" mean?
- When sshd logs 'refused connect from hostname', it means the SSH server is actively rejecting the connection attempt before authentication occurs. This is different from a timeout or port closure. deny files), which act as an additional access control layer on Linux systems.
- How do I fix "refused connect from hostname"?
- The SSH daemon (sshd) is rejecting incoming connections from a specific hostname or IP address. This typically indicates TCP wrapper restrictions, firewall rules, or service misconfiguration preventing client access.
- What causes "refused connect from hostname"?
- TCP Wrappers (hosts.deny) blocking the connecting IP address or hostname TCP Wrappers (hosts.allow) does not explicitly permit the connecting client SSH daemon was stopped or not properly started (appears running but rejects all connections)
- Is the "refused connect from hostname" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐SSH Official Documentation
- ๐ฌProxmox Forum: SSH refused connect troubleshooting(Stack Overflow)