
查看semanager是否安装执行下面命令:rpm -qa | grep semanager
如果没有安装执行下面命令:yum -y install policycoreutils-python
2 修改 ssh 配置文件
vi /etc/ssh/sshd_config
①首先把Port=22注释去掉,再把端口22更改为你想更改的端口。
3 修改 SELinux
semanage port -l | grep ssh//使用以下命令查看当前SElinux 允许的ssh端口:
( 如果没有samanager命令,yum安装:yum -y install policycoreutils-python )
4 添加 20000 端口到 SELinux
semanage port -a -t ssh_port_t -p tcp 20000
semanage port -l | grep ssh //然后确认一下是否添加进去
如果成功会输出:
ssh_port_t tcp 20000, 22
5 重启 ssh 服务执行下面命令: service sshd restart或者systemctl restart sshd.service
6、添加防火墙端口号
Linux下修改端口号只需要更改相应服务的配置文件即可,下面以修改linux 的SSH服务的默认端口号22为例(把22修改我2501):
1、修改/etc/ssh/sshd_config配置文件
[root@localhost ssh]# more sshd_config# $OpenBSD: sshd_config,v 1.69 2004/05/23 23:59:53 dtucker Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
#Port 22 //先把22注释掉
port 2501 //添加一个新的端口
#Protocol 2,1
2、重启ssh服务让修改的端口号生效
[root@localhost ~]# service sshd restartStopping sshd:[ OK ]
Starting sshd:[ OK ]
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)