CentOS7.6 修改SSH端口

1. 修改ssh配置文件

执行命令:

vi /etc/ssh/sshd_config 

首次打开发现 Port 22是被注释的

去掉前面的 #,再增加一条Port 55555,添加的监听端口号最好为10000~65535区间之内,即2的16次方

Port 22
Port 55555

这样做防止55555端口不能连接的情况下还可以使用22端口连接

防火墙放行

2.1 查看防火墙状态

firewall-cmd --state

防火墙如果关闭,则需要打开防火墙,执行命令:

# 打开防火墙
systemctl start firewalld
# 开机时启动firewall
systemctl enable firewalld.service    

2.2 防火墙放行端口 55555

firewall-cmd --zone=public --add-port=55555/tcp --permanent

2.3 重启防火墙

# 重启防火墙
systemctl restart firewalld

2.4 查看已开启端口

firewall-cmd --list-port

3. 向SELinux中添加修改的SSH端口

3.1安装SELinux的管理工具 semanage

执行命令:

yum provides semanage
# 安装运行semanage所需依赖工具包 policycoreutils-python
yum -y install policycoreutils-python

查询当前 ssh 服务端口:

semanage port -l | grep ssh

查询后如下图

image-20210117202951929

 3.3 重启ssh服务

systemctl restart sshd

测试成功后,将22端口注释掉即可!

猜你喜欢

转载自blog.csdn.net/jieyongquan/article/details/129530398