Modify SELinux
If you directly modify the ssh port without modifying SELinux, the service will not be able to restart successfully.
View SELinux status
$ sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: disabled
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
If the SELinux status is, enabled
you need to proceed to the second step 添加SSH允许端口
, otherwise you can skip the second step directly.
Add SSH allowed port
# 查看当前允许的ssh端口
$ semanage port -l | grep ssh
# 添加ssh允许端口
$ semanage port -a -t ssh_port_t -p tcp 2222
## 验证ssh端口是否添加成功
$ semanage port -l | grep ssh
ssh_port_t tcp 2222, 22
Modify ssh configuration file
$ vi /etc/ssh/sshd_config
Port 2222
$ service sshd restart