DEV Community

Cover image for Troubleshooting SSH Issues in Red Hat Linux
Alexand
Alexand

Posted on

Troubleshooting SSH Issues in Red Hat Linux

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
Enter fullscreen mode Exit fullscreen mode
  • If SSH is inactive, start it:
  sudo systemctl start sshd
Enter fullscreen mode Exit fullscreen mode
  • To enable SSH at boot:
  sudo systemctl enable sshd
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Look for:

Port 22
Enter fullscreen mode Exit fullscreen mode
  • If SSH is running on a different port, specify it when connecting:
  ssh -p 2222 user@server-ip
Enter fullscreen mode Exit fullscreen mode
  • Restart SSH after making any changes:
  sudo systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

3. Confirm Firewall Rules

A firewall blocking SSH traffic can prevent connections.

Solution:

Check firewall settings:

sudo firewall-cmd --list-services
Enter fullscreen mode Exit fullscreen mode

If SSH is not listed, enable it:

sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

If you use a custom SSH port, allow it explicitly:

sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

4. Test Network Connectivity

If SSH is unreachable, there may be network problems.

Solution:

Ping the remote server to check connectivity:

ping server-ip
Enter fullscreen mode Exit fullscreen mode

If ping fails:

  • Check the network cable or Wi-Fi.
  • Verify the server’s IP address.
  • Restart the network manager:
  sudo systemctl restart NetworkManager
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

If Fail2Ban is blocking SSH:

sudo fail2ban-client status sshd
sudo fail2ban-client unban <your-ip>
Enter fullscreen mode Exit fullscreen mode

6. Fix SSH Key Authentication Issues

If SSH key authentication fails:

  • Check permissions on key files:
  chmod 600 ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • Ensure the public key is in the correct location:
  ls ~/.ssh/authorized_keys
Enter fullscreen mode Exit fullscreen mode
  • Regenerate SSH keys if needed:
  ssh-keygen -t rsa -b 4096
Enter fullscreen mode Exit fullscreen mode

7. Verify SELinux Rules

SELinux may block SSH connections.

Solution:

Check SELinux status:

getenforce
Enter fullscreen mode Exit fullscreen mode

If enforcing, allow SSH:

sudo semanage port -a -t ssh_port_t -p tcp 22
Enter fullscreen mode Exit fullscreen mode

Restart SSH:

sudo systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)