记一次更换Centos8SSH端口的记录
备份旧SSH文件
| 12
 3
 4
 5
 6
 
 | # 创建当前时间字符串date_format=`date +%Y_%m_%d:%H:%M:%S`
 # 复制文件
 sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_$date_format
 # 可以使用命令进行确定是否备份
 ls /etc/ssh/sshd_config*
 
 | 
改变SSH监听的端口
修改对应文件
| 1
 | sudo vi /etc/ssh/sshd_config
 | 
将配置文件中的Port22注释去掉并加上自己的端口号,先不删除22是因为防止突然中断自己连不上
允许新的端口使用SSH
| 12
 3
 4
 5
 6
 
 | # 检查已使用的端口semanage port -l | grep ssh
 # 添加端口
 sudo semanage port -a -t ssh_port_t -p tcp 33000
 # 删除端口
 sudo semanage port -d -t ssh_port_t -p tcp 22
 
 | 
添加防火墙规则
| 12
 3
 4
 5
 6
 7
 8
 
 | # 添加防火墙规则sudo firewall-cmd --add-port=33000/tcp --permanent
 # 移除ssh规则
 sudo firewall-cmd --remove-service=ssh --permanent
 # 重启防火墙
 sudo firewall-cmd --reload
 # 重启sshd服务
 sudo systemctl restart sshd
 
 | 
中途出现的错误
-bash: semanage: command not found
| 12
 3
 4
 
 | # 查询什么包提供了yum provides /usr/sbin/semanage
 # 所以就安装这个
 dnf install policycoreutils-python-utils
 
 | 
参考资料
RHEL8/CentOS8的基础防火墙配置
enable_ssh_centos8
How to Fix ‘semanage command’ Not Found Error in CentOS/RHEL
semanage和SELinux的小总结