Skip to main content

Changing the SSH Port for Dedicated Servers

This article covers changing the SSH Port for Dedicated Servers.

There are several steps to take when changing the SSH Port.

  1. Log into the server in question as root through SSH.

  2. Find and enter the sshd_config file for editing.

    nano /etc/ssh/sshd_config

    Once you are in the sshd_config file, search for the current SSH Port number (using CTRL+w).

  3. Replace the Port setting with the desired port number. For this example, we will use port 2222.

    Once completed save the file and exit back into the server. (For nano, use Ctrl+X, then y, then hit the Enter key)

  4. Next, go into the firewall settings and update the incoming TCP ports to allow the new port if it is not already allowed.

    nano /etc/csf/csf.conf

    Find the incoming TCP ports, look for the requested SSH port number. If it is not there, add the new port to the list. Once complete, save and close the file.

  5. Now save the settings for the firewall.

    csf -r

    Then restart the SSH services on the server.

    /scripts/restartsrv_sshd

    You should then try disconnecting and reconnecting to the server with the new port number to verify the changes you've made actually work.