SSH is essential for securely managing remote systems, but sometimes it can fail due to misconfigurations, network problems, or security settings. Here’s a step-by-step guide to diagnosing and fixing common SSH issues in Red Hat Linux.
1. Check If SSH Service Is Running
The SSH daemon (sshd) must be active for connections to work.
Solution:
Run the following command:
sudo systemctl status sshd
- If SSH is inactive, start it:
sudo systemctl start sshd
- To enable SSH at boot:
sudo systemctl enable sshd
2. Verify SSH Port Settings
By default, SSH listens on port 22, but if the port has been changed, connections may fail.
Solution:
Check the port in the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Look for:
Port 22
- If SSH is running on a different port, specify it when connecting:
ssh -p 2222 user@server-ip
- Restart SSH after making any changes:
sudo systemctl restart sshd
3. Confirm Firewall Rules
A firewall blocking SSH traffic can prevent connections.
Solution:
Check firewall settings:
sudo firewall-cmd --list-services
If SSH is not listed, enable it:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
If you use a custom SSH port, allow it explicitly:
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
4. Test Network Connectivity
If SSH is unreachable, there may be network problems.
Solution:
Ping the remote server to check connectivity:
ping server-ip
If ping fails:
- Check the network cable or Wi-Fi.
- Verify the server’s IP address.
- Restart the network manager:
sudo systemctl restart NetworkManager
5. Check for Failed SSH Attempts
Repeated failed logins may trigger security mechanisms like Fail2Ban, blocking SSH access.
Solution:
Check logs for failed login attempts:
sudo cat /var/log/secure | grep "Failed password"
If Fail2Ban is blocking SSH:
sudo fail2ban-client status sshd
sudo fail2ban-client unban
6. Fix SSH Key Authentication Issues
If SSH key authentication fails:
- Check permissions on key files:
chmod 600 ~/.ssh/id_rsa
- Ensure the public key is in the correct location:
ls ~/.ssh/authorized_keys
- Regenerate SSH keys if needed:
ssh-keygen -t rsa -b 4096
7. Verify SELinux Rules
SELinux may block SSH connections.
Solution:
Check SELinux status:
getenforce
If enforcing, allow SSH:
sudo semanage port -a -t ssh_port_t -p tcp 22
Restart SSH:
sudo systemctl restart sshd
Summary
If SSH isn't working in Red Hat Linux, checking services, ports, firewall settings, and authentication methods will help diagnose and resolve the issue. Mastering SSH troubleshooting ensures smooth and secure remote management.