How to Change the Remote Port of a Linux Cloud Server?

12-01-2024 02:14:22

As it is widely known, the default remote port for the Linux operating system is 22. While this port provides administrators with a remote management access point, it also leaves a vulnerability for hacker attacks. Therefore, changing the default remote port of a Linux cloud server is a common strategy to enhance the security of the operating system. How do we do this? Follow the steps below.

Step One: Configure SSH

Edit the SSH configuration file:

vi /etc/ssh/sshd_config

Locate the line with "Port" and change the default port 22 to the desired port, such as 2124.

Port 2124

Step Two: Update the Firewall

This step can be skipped if a firewall is not in use. However, if the firewall is active, failing to update it after changing the remote port can result in remote access issues.

CentOS 7

firewall-cmd --add-port 2124/tcp --permanent
firewall-cmd --reload

Ubuntu

sudo ufw allow 2124/tcp
sudo ufw reload

Step Three: Restart SSH

Execute the following command to restart the SSH service.

service sshd restart

And just like that, we have successfully changed the remote port of the Linux cloud server from 22 to 2124.