Linux changes the SSH port and solves the problem of SSHD service restart failure

Environment: Linux CentOS 7

1. Enter the sshd configuration file: vi /etc/ssh/sshd_config
2. Find the line "#Port 22", delete the comment character #, and change the port to (the port number you want to change, such as: 2022): insert image description here
3. Restart the sshd service:

systemctl restart sshd

The following error messages may appear:

Job for sshd.service failed because the control process exited with error code.See "systemctI status sshd.service" and "journalctI -xe" for details.

The reason is that SELinux (a security subsystem of Linux) rejected the restart. Just temporarily turn the SELinux firewall off:

setenforce 0

Then use the "systemctl restart sshd" command to restart the service and check whether the port is enabled:

netstat -atunlp|grep sshd

It can be found that the port has been opened: insert image description here
4. Finally, the firewall allows port 2022:

firewall-cmd --zone=public --add-port="2022"/tcp --permanent

Reload the firewall when done:

firewall-cmd --reload

insert image description here
After the prompt is successful, you can access the server through port 2022.

Guess you like

Origin blog.csdn.net/qq_54042324/article/details/130939901