Jan 21, 2022
How to Change SSH Port on VPS
Even though Secure Shell (SSH) allows you to have a secure connection with your remote server, changing the standard SSH port number is necessary for the sake of your VPS security. In this article, we’ll be explaining how to change SSH port on your VPS, as well as delving deeper into why you’d want to change the port in the first place.
Reasons to Change Your SSH Port
SSH is a secure network protocol created for communication between devices across the Internet. It enables you to transmit data, commands, and even files. So, you can remotely log in and take control of another device.
The connection is commonly done via the standard SSH port 22/TCP. Consequently, the port becomes a popular target of brute force attacks – either through SSH key scanning or root account login attempts. Therefore, changing your default VPS port can add an extra layer of security. We suggest to do this right after setting up your VPS.
How to Change SSH Port?
The process is really simple.
Connect to your remote server by performing these steps:
- Run the following command in your terminal:
ssh (username)@(IP address)
Replace the (username) with your account user name, and (IP address) with your VPS IP address. For instance:
Note: If this is your first time changing the port or even using SSH, you need to confirm whether or not you’ll continue connecting to a remote device. Type yes to allow the connection.
Once you’ve established the connection, follow these steps to configure a new port number:
- Access the SSH daemon (sshd) by executing this command on your text editor. We’ll be using the vim command in this example.
- Find the line that says #Port 22 and change it to your desired port. If you’re using vim, you need to press i to enter insert mode. Only then can you delete the old port and change it. After that hit esq to exit insert mode. Type wq to save your changes and quit.
ProTip! Use port higher than 1024 as those are reserved for commonly known programs on the internet to avoid conflicts.
service sshd restart
At this point, make sure that your newly selected port is not blocked. If this is a new VPS server, all ports should be open by default.
As the standard port 22 tends to be an easy target for attackers, it’s recommended to change the default port to add extra protection to your server.
Once you’re connected to your VPS, configure a new port number via the SSH daemon. If you’ve set specific rules to your firewall, please make sure that your desired port is unblocked.
Great, now you’ve learned how to change SSH port!