天天看点

centos7修改ssh默认端口号

Xshell链接错误:Could notconnect to ‘192.168.18.128’ (port 22): Connection failed.

还有一种可能就是你的sshd服务被Gank了。可以先去服务器看下22的默认端口是否还开启

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

[[email protected]_0_2_centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
           

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

[[email protected]_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规则

[[email protected]_0_2_centos ~]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9527 -j ACCEPT

[[email protected]_0_2_centos ~]# iptables-save

[roo[email protected]_0_2_centos ~]# iptables -nL --line-number
           
centos7修改ssh默认端口号

5.重启sshd服务。systemctl restart sshd。断开连接后,需要重新填写新的ssh端口号

[[email protected]_0_2_centos ~]# systemctl restart sshd

[[email protected]_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测试看是否能正常连接

centos7修改ssh默认端口号
centos7修改ssh默认端口号

继续阅读