blog posts

SSH

How to Change SSH Port on Linux VPS?

As you know, SSH is a completely secure protocol for communicating with a remote server. However, since the standard SSH port for everyone is 22, hackers may exploit you for any reason. To ensure this and 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 a Windows operating system to connect to your Linux server, PuTTY software makes it easy for you.

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

The following 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 connect to your SSH server using an SSH client, such as the built-in OpenSSH client on Linux.

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

How to change the SSH port

Doing this requires very simple steps and 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@189.15.0.7

[highlight color=” yellow”]Note: If this is the first time you are changing the port or even using SSH, you must 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 Esc 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 to avoid interference. These ports are reserved for common applications on the Internet.

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:

1026

Note: After changing the Port on that page, you should use the keyboard’s Ctrl+O to save, then Ctrl+X to exit.

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

service sshd restart

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

Conclusion

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.