1.编辑ssh_config文件
vi /etc/ssh/sshd_config
增加端口50026,为了防止出错,保留原来的22端口
在修改默认端口时有注释提示
if you want to change the port on SELinux system,you have to tell SELinux about this change
执行下面的命令
sudo semanage port -a -t ssh_port_t -p tcp 50026
提示command not found
接下来安装semanage,执行下面的命令
yum -y install policycoreutils-python
安装完成,再执行下面的命令,允许SELinux访问新的端口
sudo semanage port -a -t ssh_port_t -p tcp 50026
2.执行以下命令将新的端口允许防火墙通过
firewall-cmd --zone=public --add-port=50026/tcp --permanent
执行以下命令重启防火墙
systemctl restart firewalld.service
查看防火墙的状态
systemctl status firewalld
重启SSH 服务
systemctl restart sshd.service
查看sshd 的状态
systemctl status sshd.service
或运行以下命令查看ssh是否在新的端口上运行
ss -tnlp | grep ssh
使用新端口登录
ssh username@服务器ip -p 50026
禁用22端口
vi /etc/ssh/sshd_config
将22端口注释掉
重启ssh服务
systemctl restart sshd.service
查看ssh运行的端口号
ss -tnlp | grep ssh