Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify the default remote port of Linux server

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

How to modify the default remote port of Linux server? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

Note: do not modify port 22 directly, first add the default remote port you need. The reason why it is set to two ports first, and then close one port after a successful test, is to log in and debug through port 22 in case the new port cannot be connected during the modification of the configuration file and the process of network debugging.

1. Connect remotely and log in to the Linux instance. For more information, see connecting Linux instances.

2. Run vim / etc/ssh/sshd_config command.

3. Press the I key on the keyboard to enter the editing state. Add a new remote service port, this section takes port 1022 as an example. Enter Port 1022 under Port 22.

4. Press the ESC key on the keyboard, enter: wq and then exit the editing state.

5. Execute the following command to restart the instance. After restarting the instance, you can log in to the Linux instance through port 22 and port 1022 SSH.

/ etc/init.d/sshd restart

6. Configure the firewall.

When using versions prior to CentOS 7 and enabling the default firewall iptables, you should note that iptables does not block access by default. If you have configured iptables rules, you need to execute the iptables-An INPUT-p tcp-- dport 1022-j ACCEPT command to configure the firewall. Then execute the service iptables restart command to restart the firewall.

Note: Firewalld is installed by default in later versions of CentOS 7. If you have enabled firewalld.service, you need to run the command firewall-cmd-- add-port=1022/tcp-- permanent to release TCP port 1022. If the returned result is success, port TCP 1022 has been released.

7. Add security group rules to the instance to allow the newly configured remote port to connect. For more information, see adding Security Group rules.

Use the SSH tool to connect to the new port to test whether it is successful or not.

Enter the modified port number in the Port text box when logging in, which is 1022 in this example.

8.2. After connecting successfully using port 1022. Run the vim / etc/ssh/sshd_config command to delete port 22.

Run the / etc/init.d/sshd restart command to restart the instance, and the remote port modification of the server is completed by default. Log in with the new port number when you log in again.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report