This guide explains how to change the default SSH port on a server using WHM. This procedure allows a server administrator to improve security by moving the SSH service to a non-standard port.
Warning: Changing the SSH port can result in a loss of remote access if the configuration is not applied correctly or if the firewall is not updated simultaneously. Ensure you have an active, out-of-band management console or a secondary way to access the server before proceeding.
Before you begin
You will need:
Root access to the WHM interface
A current, active SSH session to the server
The desired non-standard port number (typically between 1024 and 65535)
Change the SSH port in WHM
Log in to WHM.
Navigate to Software > Change SSH Port.
Enter the new port number in the SSH Port field.
Select the appropriate Port Range (usually 1024–65535 for non-standard ports).
Click Change.
Update the firewall to allow the new port
After changing the port in WHM, you must ensure the firewall allows traffic on that specific port.
In WHM, navigate to Plugins > ConfigServer Security & Firewall (CSF) (or your specific firewall management tool).
Locate the TCP_PORTS setting.
Add your new SSH port to the list of allowed ports, separated by a space.
Save the configuration.
Restart the firewall service.
Verify the new port
To confirm the change was successful without closing your current session, open a new terminal window and attempt to connect using the new port.
Use the following command to test the connection:
ssh -p [New Port Number] root@your_server_ipIf the login prompt appears, the port is correctly configured and open.
If you are locked out of the server
If you cannot connect via the new port or the old port, you must use a console (such as a VPS provider's "Console" or "VNC" access) to revert the changes.
Log in via the provider's web console.
Access the command line and check the current SSH port:
ss -tulpn | grep sshdIf the port is incorrect, edit the SSH configuration file:
nano /etc/ssh/sshd_configCorrect the
Portline to your desired value.Restart the SSH service:
systemctl restart sshd
Limitations
This procedure does not change the port for local logins; it only affects remote SSH connections.
If you use a custom SSH configuration file (e.g.,
/etc/ssh/sshd_config.d/), ensure the port is updated in the correct file.This does not change the port for other services like SFTP or SCP unless they are specifically configured to follow the SSH port.
