Changing SSH Port for WHM/ cPanel Server

SSH is the most favorate way to connect to any Linux/ cPanel server when something goes wrong, and geeks still use it even for many tasks that a novice will do through the WHM interface.

Have you ever noticed 1000s of invalid login attempts when you log in to SSH? On one of the servers we manage, it looked like this.

There were 18261 failed login attempts since the last successful login.
Last login: Tue Jan 26 01:28:48 2021 from xxx.xxx.xxx.xxx

  CentOS Linux 7 (Core)

Linux sub.server-host.net 4.19-ovh-xxxx-std-ipv6-64 #1179808 SMP Mon Mar 30 07:31:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


  Server        : 19182
  IPv4          : xx.xxx.xxx.xx
  IPv6          : xxxx:xxxx:xxx:xxxx::
  Hostname      : sub.server-host.net

On windows, we use Putty ssh client, which you can download from putty website putty.org
The best way to tackle these invalid attempts is to change the default ssh port, 22, to a custom one.

How To change the SSH port of your server.

  1. Login to your server with your favorite SSH client (we use putty)
  2. If you use a firewall (for example, CSF Config Server Security & Firewall, the best free firewall for cPanel servers), open the port in the firewall before you make a change.
  3. Edit config file for SSH
     nano /etc/ssh/sshd_config
  4. Find the line with #port 22 and (1) remove # (2) change the number. Chose a random number, or one that is easy to remember for you between 1024 to 65535. All the port numbers from 0 to 1023 are designated to famous privileged service.
    Port 9467
  5. Resetart SSH Service
    systemctl restart sshd.service
  6. Important Do not close the current SSH session yet. Logon to the server from the new putty session on the new port to ensure new arrangements are working.