CentOS Stream修改SSH端口及删除端口
1.修改SSH端口
复制代码
1
2sudo vim /etc/ssh/sshd_config
找到
复制代码
1
2#Port 22
修改为以下内容
复制代码
1
2
3Port 22 //开放默认的22端口,为了保证ssh能通过22正常登录,即使自定义端口无法正常登录也需要保证22暂时能够正常登录,方便之后操作 Port 1001 //新增的端口号
2.配置firewall(防火墙)
向firewall中添加自定义的ssh端口1001
复制代码
1
2sudo firewall-cmd --zone=public --add-port=1001/tcp --permanent //增加permanent参数代表永久性
重新加载firewall
复制代码
1
2sudo firewall-cmd --reload
查看端口是否添加成功,如果添加成功则会显示yes,否则会显示no
复制代码
1
2sudo firewall-cmd --zone=public --query-port=1001/tcp
3.修改SELinux,同时查看semanage是否已经安装,如果semanage没有安装,则无法使用semanage命令
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49sudo rpm -qa |grep policycoreutils-python # 若未安装,请先安装工具包 [root@CentOSStream9 ~]# dnf provides semanage #查看semanage在哪个安装包中 Repository baseos is listed more than once in the configuration Repository appstream is listed more than once in the configuration 上次元数据过期检查:0:22:21 前,执行于 2022年11月26日 星期六 15时11分14秒。 policycoreutils-python-utils-3.3-5.el9.noarch : SELinux policy core python utilities 仓库 :appstream 匹配来源: 文件名 :/usr/sbin/semanage policycoreutils-python-utils-3.4-1.el9.noarch : SELinux policy core python utilities 仓库 :appstream 匹配来源: 文件名 :/usr/sbin/semanage policycoreutils-python-utils-3.4-2.el9.noarch : SELinux policy core python utilities 仓库 :appstream 匹配来源: 文件名 :/usr/sbin/semanage policycoreutils-python-utils-3.4-3.el9.noarch : SELinux policy core python utilities 仓库 :appstream 匹配来源: 文件名 :/usr/sbin/semanage policycoreutils-python-utils-3.4-4.el9.noarch : SELinux policy core python utilities 仓库 :@System 匹配来源: 文件名 :/usr/sbin/semanage policycoreutils-python-utils-3.4-4.el9.noarch : SELinux policy core python utilities 仓库 :appstream 匹配来源: 文件名 :/usr/sbin/semanage [root@CentOSStream9 ~]# dnf install policycoreutils-python-utils-3.4-4.el9.noarch #安装 Repository baseos is listed more than once in the configuration Repository appstream is listed more than once in the configuration 上次元数据过期检查:0:26:16 前,执行于 2022年11月26日 星期六 15时11分14秒。 软件包 policycoreutils-python-utils-3.4-4.el9.noarch 已安装。 依赖关系解决。 无需任何处理。 完毕! [root@CentOSStream9 ~]#
4.查看selinux当前允许的端口
复制代码
1
2sudo semanage port -l |grep ssh
5.增加自定义的ssh端口1001
复制代码
1
2sudo semanage port -a -t ssh_port_t -p tcp 1001
7.检查自定义端口是否添加成功,如果成功怎会显示
复制代码
1
2sudo semanage port -l |grep ssh
8.重启相关服务
复制代码
1
2
3sudo systemctl restart sshd //ssh服务 sudo systemctl restart firewalld.service //firewall服务
9.在sshd_config中将22端口注释后重启ssh服务就可以完成所有设置。
10.firewall删除某个端口
复制代码
1
2
3
4
5firewall-cmd --zone=public --query-port=1001/tcp //先查看该端口是否存在 firewall-cmd --zone=public --remove-port=22/tcp --permanent //如果该端口存在,则删除 firewall-cmd --zone=public --query-port=22/tcp //再次查看需要删除的端口是否已经删除 firewall-cmd --reload //重新加载
11.semanage删除端口
复制代码
1
2semanage port --delete -t ssh_port_t -p tcp 5500
最后
以上就是闪闪魔镜最近收集整理的关于CentOS Stream修改SSH端口及删除端口CentOS Stream修改SSH端口及删除端口的全部内容,更多相关CentOS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复