Xshell 連線Linux虛擬機器失敗解決辦法(未開放22埠)
當我們安裝好ubuntu,用ssh遠端登入時,會出現如下錯誤。
[c:\~]$ ssh 192.168.142.84
Connecting to 192.168.142.84:22…
Could not connect to ‘192.168.142.84’ (port 22): Connection failed.
Type `help’ to learn how to use Xshell prompt.
錯誤顯示,該IP地址的22埠連線失敗。
解決方法如下:
(1)關閉防火牆,執行sudo ufw disable
[email protected]:~$ sudo ufw disable
[sudo] password for nii:
Firewall stopped and disabled on system startup
(2)安裝OpenSSH,執行sudo apt-get install openssh-server openssh-client命令。
(3)執行netstat -tnl命令,檢視22埠是否開通。
[email protected]:~$ netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
倒數第二行可以看到22埠已經處於LISTEN狀態。