BUG:WSL 的 ssh server 無法啟動


BUG

使用 sudo service ssh start 啟動 ssh 服務,提示:

 * Restarting OpenBSD Secure Shell server sshd                   
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
                                                          [ OK ]

然后使用 powershell 連接,提示 refused:

PS C:\Users\suyua> ssh ryan@localhost
ssh: connect to host localhost port 22: Connection refused

FIX

卸載重裝 openssh-server:

sudo apt-get purge openssh-server  # purge 是卸載並刪除配置文件
sudo apt-get install openssh-server

然后修改 /etc/ssh/sshd_config 的下列幾行參數:

#Port 22   # 如果端口沖突,就需要修改這個
ListenAddress localhost  # 只接受本地請求
PasswordAuthentication yes  # 允許密碼登錄

重啟 ssh 服務:

sudo service ssh restart

然后連接:

PS C:\Users\suyua> ssh ryan@localhost
ryan@localhost's password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.4.0-17763-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

......

問題解決。

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM