Explore the fun of station building and operation and maintenance

Record the complete Linux SSH port modification process

Generally, the ECS port we start with is 22 by default, which is really not secure from a security perspective. We need to modify the port to a custom port. Generally, conditional friends will change the port to a user-defined number, provided that it does not conflict with the ports of some systems.

 Record the complete Linux SSH port modification process

1. Edit the SSH configuration file/etc/ssh/sshd_config. You can use any text editor, such as vi or nano. Execute the following command to open the file using the vi editor:

 sudo vi /etc/ssh/sshd_config

2. Find the # Port line in the open configuration file (commented out by default). If the line cannot be found, add the following line at the end of the file:

 Port<new SSH port number>

3. Replace<New SSH port number>with the new SSH port number you want to set, and make sure to select a port number that is not occupied by other services.

Save and close the file. In the vi editor, press Esc and enter: wq to save and exit.

Reload the SSH configuration for the changes to take effect. Execute the following command:

 sudo systemctl reload sshd

If your server has a firewall (such as iptables or firewalld), make sure that the new SSH port is allowed to pass through the firewall.

4. After modifying the SSH port, retest the SSH connection to ensure that you can successfully connect to the new SSH port. Use the following command to connect in the SSH client:

 Ssh<username>@<server IP address>- p<new SSH port number>

Replace<user name>with your user name,<server IP address>with the server IP address, and<new SSH port number>with the new SSH port number you set.

Please note that after modifying the SSH port, remember to update any relevant firewall rules, port forwarding rules on network devices, and port settings in the remote connection tool you use.

Like( zero )
Reprint reservation: Old Tribe » Record the complete Linux SSH port modification process


Follow the public account "Chiang Kai shek's circle of friends"

Get more new knowledge about station building, operation and maintenance!
Internet entrepreneurship, cutting-edge technology