How to Change SSH Port on VPS
access_time
hourglass_empty
person_outline

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.

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

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.

How to Change SSH Port?

The process is really simple.

Connect to your remote server by performing these steps:

  1. 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:

    ssh username@189.15.0.7

    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.

  2. Input your password and click Enter.

Once you’ve established the connection, follow these steps to configure a new port number:

  1. Access the SSH daemon (sshd) by executing this command on your text editor. We’ll be using the vim command in this example.
    vim /etc/ssh/sshd_config
  2. 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.

  3. Set up your new port number below the old one by removing the hashtag and typing in the new desired number, for instance:
    1026
  4. After changing the port, you need to restart SSH daemon using this command:
    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.

Conclusion

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!

The Author

Author

Edgaras G. / @edgaras

Edgaras is a veteran server administrator at Hostinger. He makes sure that every server runs at full throttle and has all the latest technological advancements. When he's not working, Edgaras enjoys skiing and exploring the world.

Related tutorials

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in VPS
How to Migrate From Shared Hosting to VPS With cPanel

Close