How To Change SSH Port On Linux VPS

How To Change SSH Port On Linux VPS


One of the steps to secure your VPS is to change the default SSH port. Once you start using a non-default port, all connections to the default port will be denied, thus increasing chances of your VPS to stay away from common SSH scanners used by hackers. You will learn what needs to be changed in the VPS configuration in order to use a custom SSH port.

What you’ll need

Before you begin this guide you’ll need the following:

  • SSH root access to the VPS

Changing the port

Open configuration file of the SSH daemon by executing the following command:

nano /etc/ssh/sshd_config

Alternatively, you can use vim editor (it’s installed by default on all Linux distributions):

vim /etc/ssh/sshd_config

Locate this line:

# Port 22

Change it to any port you desire and remove # at the beginning. Save the changed file with CTRL+X (or COMMAND+Xshortcut if you are on MAC).

In order for changes to take effect, you need to restart SSH daemon with this command:

service sshd restart

All is set, you have just changed your default SSH port. Do not forget that from now on you will be able to access the server only using the port that you have specified in the configuration.


Congratulations, you have just learned how to change SSH port and greatly increased the security of your server! This tutorial is one in the series of how to secure your VPS, do not hesitate to check them all.

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.