Home >Operation and Maintenance >Linux Operation and Maintenance >Modify the default remote port 22 of the Linux server
This section uses CentOS 6.8 as an example to introduce how to modify the default remote port of the Linux server.
Note: Do not modify port 22 directly, first add the required default remote port. The reason why we first set up two ports and then close one port after the test is successful is that in the process of modifying the configuration file and network debugging, if the new port cannot be connected, we can still log in and debug through port 22.
1. Connect remotely and log in to the Linux instance. For specific operations, see Connecting to a Linux Instance.
2. Run the 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 and enter: wq
to 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 SSH on port 22 and port 1022.
/etc/init.d/sshd restart
6. Configure the firewall.
When using versions prior to CentOS 7 and turning on the default firewall iptables, you should note that iptables does not intercept access by default. If you configure iptables rules, you need to execute iptables -A INPUT -p tcp --dport 1022 -j ACCEPT
command configures the firewall. Then execute the service iptables restart
command to restart the firewall.
Note: Firewalld is installed by default in CentOS 7 and later versions. If you have enabled firewalld.service, you need to run the command firewall-cmd --add-port=1022/tcp --permanent to release TCP 1022 port. If the return result is success, it means that TCP port 1022 has been released.
7. Add security group rules for the instance to allow the newly configured remote port to connect. For specific operations, see Adding Security Group Rules.
8. Use the SSH tool to connect to the new port to test whether it is successful.
8.1. When logging in, enter the modified port number in the Port text box, which is 1022 in this example.
8.2. After successful connection using port 1022. Run the vim /etc/ssh/sshd_config
command to delete port 22.
8.3. Run the /etc/init.d/sshd restart
command to restart the instance. The server default remote port has been modified. Just use the new port number to log in again.
Recommended tutorial: linux tutorial
The above is the detailed content of Modify the default remote port 22 of the Linux server. For more information, please follow other related articles on the PHP Chinese website!