天天看点

Linux 修改ssh端口 | Bind to port 2222 on 0.0.0.0 failed: Permission denied修改配置文件防火墙放行SELinux添加修改的SSH端口重启服务

文章目录

  • 修改配置文件
  • 防火墙放行
  • SELinux添加修改的SSH端口
  • 重启服务

修改配置文件

vi /etc/ssh/sshd_config
           
  • 添加2222
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
Port 22
Port 2222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
           

防火墙放行

firewall-cmd --zone=public --add-port=2222/tcp --permanent
firewall-cmd --reload
           

SELinux添加修改的SSH端口

如果不修改SELinux直接重启sshd,会出现

Bind to port 2222 on 0.0.0.0 failed: Permission denied

错误

  • 安装管理工具
yum -y install policycoreutils-python
           
  • 新增selinux中sshd的端口
semanage port -a -t ssh_port_t -p tcp 2222
           

重启服务

systemctl restart sshd