SSH Connection Not Opening After Reboot? Permanent Solution on WHM/cPanel Servers
Introduction
There are some occasions when a reboot on WHM/cPanel based servers results in SSH access being severed, and remote connection fails. This is a critical problem, especially for remote management system administrators. Some of the root causes of the problem are:
SSH service not configured to start on system boots
Firewall (especially firewalld) setting blocks SSH port
Errors in SSH configuration file
Static IP or DNS problems in network configurations.
This article deals with the issue of not opening an SSH connection after reboot in detail, leading to understanding the causes as well as implementing a permanent solution.
Symptoms of the Problem
There is no response to the command ssh root@ip-address.
Ping is working, but connection is not established.
The WHM panel may be up and running, but SSH port (22) does not seem to be listening.
When connected through VDS/VPS provider panel, the sshd service may not be running.
1. Possible Causes
1.1 SSH Service Not Starting
On some servers, the sshd service might not have been initialized during the system startup.
1.2 Firewalld Configuration
firewalld, at boot, can close all ports and open only some: if you try connecting to SSH (port 22), by default, if it is not appended, it is rejected.
1.3 NetworkManager Conflicts
On CentOS/AlmaLinux/RHEL-based systems, NetworkManager can overwrite some settings.
2. Emergency Measures from the WHM Panel (if the Panel is Available)
If you can get into WHM:
Go to WHM > Terminal.
Enter the following commands one by one:
sudo systemctl restart sshd sudo systemctl enable sshd
If the firewall is open:
sudo firewall-cmd --permanent --add-port=22/tcp sudo firewall-cmd --reload
Thus, SSH will be opened again.
3. Step by Step Guide for Permanent Solution
3.1 Make SSH Service Permanently Active
sudo systemctl enable sshd
This command makes sure that the sshd service will start automatically on every system startup.
3.2 Immediate Start of SSH Service
sudo systemctl restart sshd
This command allows for instant restarting of the SSH service.
3.3 Permanently Open SSH Port Through Firewalld
sudo firewall-cmd --permanent --add-port=22/tcp
This would ensure that port 22 (SSH) remains open in the firewall permanently. Then:
sudo firewall-cmd --reload
Reload the firewall configuration to apply changes.
4. Alternative Scenario: If SSH Port Was Changed
If SSH port was changed (for example, to 2222) in the file /etc/ssh/sshd_config, be sure to open that port in the firewalld:
sudo firewall-cmd --permanent --add-port=2222/tcp sudo firewall-cmd --reload
Also check the sshd_config file:
sudo nano /etc/ssh/sshd_config
The following line should be correctly added:
Port 2222
Then restart the SSH service after changing:
sudo systemctl restart sshd
5. What to do if you're not able to access remotely?
If your VDS/VPS provider gives you a KVM console (terminal panel) then you can log in via that panel and follow the above steps.
Other rendered-conditions: