24/7 Australian Sales & SupportCall 13 24 85
View all Products Close Menu Menu
Changing the SSH port on your VPS
Updated Monday November 9th 2020 / Category VPS

Before completing these steps, login to your VPS via SSH.

Changing the SSH Port

    1. Open the SSH configuration file in Nano by typing in this command:
      nano /etc/ssh/sshd_config
    2. Navigate down the lines using your arrow keys, and un-comment the line in the file that says “#Port 22″.
      1. Use the backspace or delete key to remove the hash character.
      2. Change 22 to your desired port number.
    3. Then, exit Nano:
      1. Press Ctrl+X (Command+X on Mac) to quit.
      2. Then, press Y to confirm your changes
      3. Press the Enter key to confirm that the filename remains the same (do not change this).
    4. Restart the SSH daemon:
      1. On CentOS 6:
        service sshd restart
      2. On CentOS 7 and Ubuntu 18+:
        systemctl restart sshd

Updating your firewall settings

If you have a firewall set up on the server, you will need to ensure that you adjust your firewall settings to allow for connections on the new SSH port.

If you have CSF installed (cPanel servers)

  1. Open the CSF config file
    nano /etc/csf/csf.conf
  2. Look for the allowed TCP ports (approximately line 138).
  3. Use the arrow keys to navigate the cursor after one of the separating commas.
  4. Type in your new port number here and add a comma if there are any values after this.
  5. Press Ctrl+X (Command+X on Mac) to quit.
  6. Then, press Y to confirm your changes.
  7. Press the Enter key to confirm that the filename remains the same (do not change this).
  8. Restart CSF using the following command:
    csf -r

If you’re using FirewallD (CentOS 7/8, Ubuntu 18+)

Note: In this example, the new SSH Port is 2222. Make sure you adjust the port number for your use case.

Please replace port=2222 with your new nominated port.

sudo firewall-cmd --permanent --zone=public --add-port=2222/tcp
sudo firewall-cmd --reload

Can’t find the answers you're looking for? Check out these other methods of support!