安装openssh-server (有可能不需要做)
sudo apt-get update
sudo apt-get install openssh-server
启动
直接启动会报一系列ssh的key找不到的错误
john@HP303:~$ sudo service ssh restart
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
需要如下方式生成
sudo ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key
sudo ssh-keygen -t ed25519 -b 256 -f /etc/ssh/ssh_host_ed25519_key
sudo ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key
sudo ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_root_rsa_key
此时,即可完成启动:
john@HP303:/etc/ssh$ sudo service ssh restart
* Restarting OpenBSD Secure Shell server sshd
打开22端口及设置密码登录:
因为安全原因,WSL并没有开放22端口及设置密码登录,可以打开配置文件:sudo vim /etc/ssh/sshd_config,做如下配置:
Port 22
PasswordAuthentication yes
按 esc,输入:wq保存并退出
重新启动
sudo service ssh restart
作者:JohnYuCN
链接:https://www.jianshu.com/p/f8efebebebe2
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。