How to Restart SSH on a cPanel Server with a Non-Default Port
If you’ve changed the default SSH port (Port 22) on a cPanel-powered server, you may encounter issues when trying to restart the SSH service (sshd
) from WHM. This is because WHM expects SSH to be running on the default port. To resolve this, you’ll need to manually restart sshd
via SSH or temporarily reset the port back to 22.
Why Restarting SSH from WHM Fails
When you change the default SSH port, WHM can no longer communicate with the SSH service on port 22. As a result, attempting to restart sshd
from WHM will fail. To restart the service, you’ll need to connect to the server via SSH and issue the restart command manually.
Steps to Restart SSH Manually
- Connect to the Server via SSH:
Use your SSH client to connect to the server using the new SSH port. For example:ssh username@server_ip -p NEW_PORT
Replace
NEW_PORT
with the port number you’ve configured for SSH. - Restart the SSH Service:
Once connected, run the following command to restartsshd
:/sbin/service sshd restart
This command will restart the SSH service, applying any configuration changes you’ve made.
Temporarily Reset SSH Port to 22
If you’re unable to connect to the server using the new SSH port, you can temporarily reset the port back to 22 using the following steps:
- Access the AutoFixer Tool:
Open your browser and enter the following URL in the address bar:SERVER_MAIN_IP:2087/scripts2/doautofixer?autofix=safesshrestart
Replace
SERVER_MAIN_IP
with your server’s main IP address. - Restart SSH Manually:
After resetting the port, connect to the server via SSH on port 22 and restart the SSH service using the command:/sbin/service sshd restart
Important Notes
- Security Considerations: Changing the default SSH port can improve security by reducing the number of brute-force attacks. However, ensure you update your firewall rules to allow connections on the new port.
- Permanent Changes: If you want to permanently change the SSH port, update the
Port
directive in the SSH configuration file (/etc/ssh/sshd_config
) and restart the SSH service. - Backup Configuration: Always back up your SSH configuration file before making changes to avoid losing access to your server.
Final Thoughts
Changing the default SSH port on a cPanel server can enhance security, but it requires additional steps to manage the SSH service. By following the instructions above, you can restart sshd
manually or temporarily reset the port to 22 if needed. Always ensure your server remains accessible and secure when making such changes.