VPS
··2 minute readChanging the SSH port on your VPS
Before completing these steps, login to your VPS via SSH.
Changing the SSH Port
By default, SSH runs on port 22. Changing the SSH port can help reduce the number of automated attacks on your server. However, please note that this is not a comprehensive security measure and should be used in conjunction with other security practices. To change the SSH port, please follow the steps below:- Open the SSH configuration file in Nano by typing in this command:
nano /etc/ssh/sshd_config
- Navigate down the lines using your arrow keys, and un-comment the line in the file that says "#Port 22".
- Use the backspace or delete key to remove the hash character.
- Change 22 to your desired port number.
- Then, exit Nano:
- Press Ctrl+X to quit.
- Then, press Y to confirm your changes
- Press the Enter key to confirm that the filename remains the same (do not change this).
- Restart the SSH daemon:
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)- Open the CSF config file:
nano /etc/csf/csf.conf
- Look for the allowed TCP ports (approximately line 138).
- Use the arrow keys to navigate the cursor after one of the separating commas.
- Type in your new port number here and add a comma if there are any values after this.
- Press Ctrl+X to quit.
- Then, press Y to confirm your changes.
- Press the Enter key to confirm that the filename remains the same (do not change this).
- Restart CSF using the following command:
csf -r
sudo firewall-cmd --permanent --zone=public --add-port=2222/tcp
sudo firewall-cmd --reload