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:
Alternatively, you can use vim editor (it’s installed by default on all Linux distributions):
Locate this line:
# Port 22
Change it to any port you desire and remove
# at the beginning. Save the changed file with
COMMAND+X shortcut 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.