Home > Hosting > Server

How to change the remote port of a Linux cloud server

2023-07-26 16:12:09

This article introduces the knowledge about how to change the remote port of the Linux cloud server. During the operation of the actual case, many people will encounter such a dilemma. Next, let the editor guide you to learn how to deal with it These situations! I hope you read it carefully and learn something!

Step 1: Configure SSH

Edit SSH configuration file:

vi /etc/ssh/sshd_config

Find the Port line, and change the default 22 to the desired port, such as 2124.

Port 2124

Step 2: Update the firewall

If no firewall is used, this step can be ignored. If the firewall is enabled, if the firewall is not updated after changing the remote port, it will result in failure to remote.

CentOS 6

iptables -I INPUT -p tcp --dport 2124 --syn -j ACCEPT service iptables save semanage port -a -t ssh_port_t -p tcp 2124

CentOS 7

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

Step 3: Restart SSH

Execute the following command to restart the SSH service.

service sshd restart

In this way, we successfully changed the remote port of the Linux cloud server from 22 to 2124.

This is the end of how to change the remote port of the Linux cloud server, thank you for reading. If you want to know more industry-related knowledge, you can pay attention to the Yisuyun website, and the editor will output more high-quality practical articles for you!


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us