blog posts

How to Change SSH Port on Linux VPS?

As you know, SSH is a completely secure protocol for communicating with a remote server. But considering that the standard SSH port for everyone is 22, you may be exploited by hackers for any reason. To ensure this and ensure security, we suggest that you change the SSH port of your VPS.

Like FTP, there are different ways to connect to SSH. If you are using Windows operating system to connect to your Linux server, PuTTY software has made it easy for you.

Enter this link to see how to connect to SSH with PuTTY software.

In the following, we will examine the reasons for changing the SSH port.

Reasons for changing the SSH port

SSH is a secure network protocol developed for communication between devices across the Internet. It allows you to transfer information, commands, and even files. So, you can log in remotely and take control of another device.

To establish remote access, you must use an SSH client, such as the built-in OpenSSH client on Linux, to connect to your SSH server.

Connection is usually made via standard SSH port 22/TCP. As a result, port persistence becomes a popular target for brute-force attacks by hackers. So, changing your default VPS port can add a layer of security. Changing the SSH port immediately after setting up and purchasing your VPS is recommended.

How to change the SSH port

Doing this has very simple steps and requires special skills. Carefully follow our instructions to achieve the desired result.

First, we need to connect to SSH. We can do this with PuTTY software (click), and with the following method:

ssh (username) @ (IP address)

Instead of (username), enter your username and instead of (IP address), enter the IP address of your virtual server.

for example:

ssh username@

[highlight color=”yellow”]Note: If this is the first time you are changing the port or even using SSH, you will need to confirm if you are continuing to connect to a remote device. Type yes to allow the connection.[/highlight]

Enter your password and press Enter.

Once the connection is established, follow these steps to configure the new port number:

1. Access the SSH daemon (sshd) by running this command in your text editor. In this example, we will use the vim command.

nano /etc/ssh/sshd_config

2. Find the line where it says #Port 22 and change it to your desired port. If you’re using vim, you’ll 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 the insert mode. Type wq to save your changes.

Note: The default and standard SSH port for connecting to servers is 22.

Important note: use ports higher than 1024, because these ports are reserved for common applications on the Internet to avoid interference.

After entering the Code you will see this page.



3. By removing the hashtag and typing the desired number, set your new port number under the old number. For example, we use 1026 here:


Note: After Changing Port in that page you should use this keyboards Ctrl+O for saving then Ctrl+X for Exit.

4. After changing the port, you need to restart the SSH Daemon using this command:

service sshd restart

At this point, make sure that the new port you selected is not blocked. Of course, if it’s a new VPS server, all ports should be open by default.


Since the standard port 22 is an easy target for hackers, it is recommended that you change the default port to add more security to your server.

We hope you enjoyed this practical tutorial.