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
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL5QTNxETM1ETMzEDNwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
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測試看是否能正常連接配接