centos 6 7 8 修改与查看SSH远程端口
前言
ssh服务区默认使用22做为通信端口,这就给安全造成了很多挑战,开放互联网下目前很多黑客会根据弱口令进行爆破,基于此前提下修改服务器默认的ssh端口很有必要。
开始
查看SSH端口
查看服务器当前SSH使用的端口非常简单 我们可以通过一个简单的命令进行查询
netstat -nptl
运行上面的命令 即可查询到服务器当前的SSH端口
[root@s13-16 ~]# netstat -nptl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 29577/sshd
tcp6 0 0 :::22 :::* LISTEN 29577/sshd
[root@s13-16 ~]#
根据终端打印的信息 我们这里可以获取到一些重要的信息
tcp6 0 0 :::22 :::* LISTEN 29577/sshd
通过此条信息即可判断当前服务器使用的SSH端口为:22
修改SSH端口
编辑ssh配置文件 路径在:/etc/ssh/sshd_config
vi /etc/ssh/sshd_config
找到以下端口配置选项信息
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
我们需要修改的配置项即:#Port 22
新建Port配置 配置值为你需要修改的端口 如下
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
Port 2212
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
其中2212 即为新修改的端口
保存提交 重启SSH服务
systemctl restart sshd.service
重启完成以后 使用命令 netstat -nptl 验证以下
[root@s13-16 init.d]# netstat -nptl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:2212 0.0.0.0:* LISTEN 51431/sshd
tcp6 0 0 :::2212 :::* LISTEN 51431/sshd
[root@s13-16 init.d]#
可以看到 SSH端口已经成功修改为:2212
扩展阅读
修改SSH端口后远程不了
这种情况一般是防火墙里面没有放行新的SSH端口 解决方法为关闭防火墙或者在防火墙里面放行修改的端口即可
- END -
猜你喜欢
发表评论

暂无评论,你要说点什么吗?