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 sshd2. 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_configLook 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 sshd3. Confirm Firewall Rules
A firewall blocking SSH traffic can prevent connections.
Solution:
Check firewall settings:
sudo firewall-cmd --list-servicesIf SSH is not listed, enable it:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reloadIf you use a custom SSH port, allow it explicitly:
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload4. Test Network Connectivity
If SSH is unreachable, there may be network problems.
Solution:
Ping the remote server to check connectivity:
ping server-ipIf ping fails:
- Check the network cable or Wi-Fi.
- Verify the server’s IP address.
- Restart the network manager:
sudo systemctl restart NetworkManager5. 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 unban6. 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 40967. Verify SELinux Rules
SELinux may block SSH connections.
Solution:
Check SELinux status:
getenforceIf enforcing, allow SSH:
sudo semanage port -a -t ssh_port_t -p tcp 22Restart SSH:
sudo systemctl restart sshdSummary
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.