修改配置文件

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

一站式 AI 云服务平台

更多推荐