修改配置文件

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
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐