Secure your Server by Changing SSH Port


There are individuals in the internet want to find SSH servers; they will start probing each IP address on port 22 (the default SSH port). Then, once they have their list of IP addresses with port 22 open, they will start their password brute force to guess the password to have root access to those servers.
While there are many ways to make your server secure, changing default SSH port would be a basic security measure that you could take to cover your bases.

Follow these steps orderly to achieve this.

1. Connect to your server via SSH as root user using an SSH client (E.g  PuTTY).

If you have any problem with this step, refer to my tutorial on “Make First Connection to your VPS Server“.

2. Run following commands to install nano editor to your server. However, if you are familiar, you can use the default vi editor.


apt-get update
apt-get install nano


yum update
yum install nano

3. Then, open /etc/ssh/sshd_config file using nano editor.

nano /etc/ssh/sshd_config

4. Locate the following line containing “Port 22”.

The default SSH port number

5. If above line is commented, un-comment it by removing # at the beginning.

Un-comment  the line specifying the default SSH port number (22)

6. After that, change SSH port 22 to your desired port number, here in this example I am changing it to 567.

Change the port number

Important: Be sure that you do not pick a port number that is in use by a different service. If you are unsure, Wikipedia has a list of port numbers and their uses.

7. Press Ctrl + x, then y, finally Enter to save changes and exit.
8. Issue following command to restart sshd service.
service sshd restart

Now you have successfully changed your servers’ SSH port. Remember to specify the new SSH port, when you are connecting to your VPS in future.

Note: If you are under a firewall, then you have to allow newly configured port in the server’s firewall.

If you face any problem with above tutorial , let me know at the comment section 🙂

Leave a Comment

Your email address will not be published.

You may also like

Hot News