BUG:WSL 的 ssh server 沒法啓動

BUG

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

* 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:ubuntu

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

FIX

卸載重裝 openssh-server:windows

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

而後修改 /etc/ssh/sshd_config 的下列幾行參數:ssh

#Port 22   # 若是端口衝突,就須要修改這個
ListenAddress localhost  # 只接受本地請求
PasswordAuthentication yes  # 容許密碼登陸

重啓 ssh 服務:.net

sudo service ssh restart

而後鏈接:rest

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

......

問題解決。code

參考

-windows-wsl sshd配置server

相關文章
相關標籤/搜索