How to change the SSH port on a WHM Server

Background

It’s essential to change the default port on any Linux server to avoid dictionary and brute force attacks. The steps to change the port in WHM consists of two steps:

  1. Ensure the new port is open on the firewall
  2. Change the Port parameter in /etc/ssh/sshd_config and restart SSH

In most circumstances you want to follow this procedure in the correct order.

Ensure New Port is Open on the Firewall

For the purpose of increased security, we won’t dictate which port to use, but safe to say, choose something random, e.g. 427822.

WHM can have different firewall technologies installed, but if you’re using CSF:

Log into WHM
ConfigServer Security&Firewall
Scroll to Firewall Configuration
Search TCP_IN

Add the new port e.g. 47822 to existing allowed ports and save.

Change the Port parameter in /etc/ssh/sshd_config and restart SSH

SSH to your server
vi /etc/ssh/sshd_config
/ search for Port
Change the value from #22 or whatever it is to 47822

Restart SSH

service sshd restart

Locked out of SSH on your WHM Server?

If you are locked out due to a problem with the port on your SSH server, execute the following script as root:

http://serverip:2086/scripts2/doautofixer?autofix=safesshrestart

This will reset the SSH port back to 22.

References

How to reset SSH port from WHM

How to Change the SSH Port with WHM

Share this article

2 thoughts on “How to change the SSH port on a WHM Server”

  1. There’s a typo in the instructions:

    In the Heading says “Change the Port parameter in /etc/ssh/sshd_config and restart SSH” but in the next line says “vi /etc/ssh/ssh_config”. Is a d missing the sshd_config file.

    1. Eugène van der Merwe

      Hi @Andrés,

      Thanks so much for pointing out this rather bad typo! I have just corrected the line to say `sshd`. This is an import change because there actually is a file called ssh_config without the “d”! Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top