问题
CentOS7 修改sshd默认端口为2022,重启sshd结果一直报错 ``
问题根源
启动了selinux导致
[root@host~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
[root@host~]#
解决办法
将新端口加入到 selinux
[root@ip-172-30-0-30 ~]# semanage port -a -t ssh_port_t -p tcp 2022
没有semanage,yum安装一个
yum install policycoreutils-python
搞好之后,检查一下
[root@ip-172-30-0-30 ~]# semanage port -l | grep ssh
ssh_port_t tcp 2022, 22
别忘了重启 sshd
systemctl restart sshd
参考来源:https://ddewaele.github.io/networking/ssh/changing-the-ssh-port/