修改配置文件
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

本文介绍如何修改SSH默认端口并确保SELinux兼容性。通过编辑配置文件、设置防火墙规则及使用SEManage更新SELinux策略,实现SSH服务的安全增强。
2万+

被折叠的 条评论
为什么被折叠?



