Applies To: Linux System
Category: Troubleshooting → Server Connectivity, Network
Issue Summary
Users are unable to establish an SSH connection to a specific remote host, receiving errors like “Connection refused”, “Connection timed out”, or “Permission denied.”
Possible Cause(s)
List common reasons why this issue may occur.
The remote host is down or unresponsive.
SSH service (sshd) is not running on the remote host.
Firewall blocking SSH port (default 22) on either client or server.
Incorrect IP address or hostname.
Network connectivity issues between client and server.
Incorrect SSH key permissions or missing keys on client/server.
Incorrect username or password.
SSH configuration issues on the server (e.g., sshd_config).
Step-by-Step Resolution
1. Check SSH Client Logs/Verbosity:
While taking access to the server, add a verbose flag for more details.
ssh -v <user>@<hostname>
2. Verify Remote Host Status:
Ping the remote host's IP address. If there is no response, the host might be down or unreachable.
ping <hostname>
If possible, check the physical status of the remote host.
3. Check SSH Service Status on Remote Host (if accessible by other means):
If you can access the host via console or another method, check if sshd is running.
sudo systemctl status sshd
If sshd is not running, try starting it.
sudo systemctl start sshd
4. Check Network Connectivity and Port:
From the client, use telnet. If it hangs or refuses, a firewall or network issue is likely to occur.
telnet <hostname_or_ip> 22
Check firewall rules on both client and server.
sudo firewall-cmd --list-all
5. Verify IP Address/Hostname:
Double-check the IP address or hostname being used.
To check the IP address:
ifconfig
To check the hostname:
hostname -f
Ensure DNS resolution is working correctly.
nslookup <hostname>
6. Verify Authentication Method:
Password: Ensure correct username and password.
Key-based:
Check permissions for ~/.ssh and ~/.ssh/id_rsa. They should be 700 and 600, respectively.
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/id_rsa
Ensure the public key is correctly added to ~/.ssh/authorized_keys on the remote host.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Check permissions of ~/.ssh/authorized_keys on the remote host (should be 600).
sudo chmod 600 ~/.ssh/authorized_keys
7. Review sshd_config on Remote Host:
Examine /etc/ssh/sshd_config for directives that might be restricting access (e.g., AllowUsers, DenyUsers, AllowGroups, Port, PasswordAuthentication no, PermitRootLogin no).
cat /etc/ssh/sshd_config
Restart sshd after any changes.
sudo systemctl restart sshd
Additional Notes:
Always try to access the host from another client, if possible, to rule out client-side issues.
If the issue is specific to one user, focus on their .ssh directory permissions and authorized_keys file.