centos7修改ssh默认端口号

Xshell链接错误:Could notconnect to ‘192.168.18.128’ (port 22): Connection failed.
还有一种可能就是你的sshd服务被Gank了。可以先去服务器看下22的默认端口是否还开启

1.查看版本当前操作系统发行版信息 cat /etc/redhat-release

[root@VM_0_2_centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

2.编辑配置文件。vim /etc/ssh/sshd_config。去掉注释,并修改为新的端口号,保存并退出

[root@VM_0_2_centos ~]# vim /etc/ssh/sshd_config 
17 #Port 22  #默认是打开22端口
18 Port 9527 #新增自己自定义端口

3.在防火墙上放开自定义端口。 #iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9527 -j ACCEPT

#iptables-save #保存iptables规则

[root@VM_0_2_centos ~]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9527 -j ACCEPT

[root@VM_0_2_centos ~]# iptables-save

[root@VM_0_2_centos ~]# iptables -nL --line-number

在这里插入图片描述
5.重启sshd服务。systemctl restart sshd。断开连接后,需要重新填写新的ssh端口号

[root@VM_0_2_centos ~]# systemctl restart sshd

[root@VM_0_2_centos ~]# ss -ntl
State       Recv-Q Send-Q                       Local Address:Port                            Peer Address:Port              
LISTEN      0      511                          127.0.0.1:9000                                    *:*                  
LISTEN      0      128                            *:111                                           *:*                  
LISTEN      0      511                            *:80                                            *:*                  
LISTEN      0      128                            *:9527                                          *:*                  
LISTEN      0      90                            :::3306                                         :::*                  
LISTEN      0      128                           :::111                                          :::*     

6.xshell测试看是否能正常连接
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值