October 3, 2024
How to Change the Default SSH Port on a Linux VPS

How to Change the Default SSH Port on a Linux VPS

If you have a server, you should change the SSH port to increase the security of the Cloud VPS while avoiding automatic attacks or brute force attacks. The reason is, that SSH or Secure Shell is a network protocol that is used to log in remotely (remote) securely.

Then, how to change the SSH port? Don’t get me wrong, first understand the complete guide in the following article!

Table of Contents

Why is SSH port switching important?

Changing the SSH port is something that is considered important because the port that is currently often used for SSH, namely port 22 is no longer secure because many people already know about it.

The following port changes are made to prevent random people from trying to log in ( brutal force login ), so they can’t do it, because only you know about the port in Linux. This will also prevent your device from hacker attacks.

How to change the SSH port

3 easy ways can help you change the port in SSH. These methods include the following.

1. How to change the port for SSH with the “Sed” command on the VPS

First, you can change the port on SSH by looking for port number 22. Then how to change the SSH port is, you just need to follow the following command:

$ sed -i ‘s/#Port 22/Port 65001/’ /etc/ssh/sshd_config

Port 65001 is the new port that will be used later. This means that port 65001 will replace port 22.

Second, you have to reset the SSH that you will use because the port will not run until you restart. So, all you have to do is type the following on your VPS:

$ systemctl restart sshd

Third, you can access port 65001! You can directly check whether your configuration is successful or not by inputting PUTTY and entering port 65001.

2. How to change SSH port with Cloud VPS

Next, you can also change the port for SSH with Cloud VPS, the friend. The first thing you have to do is open the configuration file with either nano or vim. Here’s how to find out the SSH port:

With nano : nano /etc/ssh/sshd_config

With vim : vim /etc/ssh/sshd_config

Second, you can immediately slide to look for port 22 which reads “#Port 22”.

Third, remove the # sign, and replace the number 22 with the port you want. As a suggestion, you can replace it with a value range between 49152-65535 for the private category. Don’t forget to save the changes you made by pressing ctrl + X press Y then enter, OK!

3. How to change the SSH port with Policycoreutils

First, the SSH port is something that is configured, so you have to open its configuration file first, using Vi with the command:

# vi /etc/ssh/sshd_config

Second, just like the previous step, you just need to change port 22 to a new port. Don’t forget to first find out where #Port 22 is located. You can change the port randomly, but try more than 1024 and less than 65535/TCP, bro!

Third, you can restart your SSH Daemon by using the command:

$ systemctl restart sshd or $ service sshd restart

Next for CentOS and RHEL Linux users, you can install the Policycoreutils package to loosen Linux, so that the new port you want can run smoothly.

In addition, Policycoreutils can also cause the rules that you create to be permanent so that the rules will not change even if your device is restarted. That’s a complete guide on how to change the SSH port that you can apply. How easy isn’t it?

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *