Windows 10内置Ubuntu子系统安装SSH服务
第一步,打开Ubuntu命令行窗口,切换到root用户,安装tasksel程序并执行:
# apt install tasksel -y # tasksel
出现下面这个紫色的小窗口:
看着很简单,试着启动一下就出错了。
# /etc/init.d/ssh start * Starting 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
不过这个难不倒人,简书上就有大神给出了解决方案,这是因为新版的opensshd 中添加了ed25519 做签名验证,而之前系统里没这个算法的证书。生成一下再次启动,这次就OK了
# ssh-keygen -A ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519 # /etc/init.d/ssh start * Starting OpenBSD Secure Shell server sshd [ OK ]
windows 10安装PuTTy客户端工具
PuTTy 是最有名的 SSH 和 telnet 客户端,最初由 Simon Tatham 为 Windows 平台开发。非常易于安装和使用,通常大部分的配置选项你都不需要修改。只需要输入少量基本的参数,就可以开始很简单地建立连接会话。
另找一台局域网内的电脑(下称电脑B),作为客户端远程连接装有Ubuntu的电脑(下称电脑A),在电脑B上点此下载 PuTTy最新版(0.71)。根据你的操作系统选择64位或32位版本安装即可,我选64位版本。安装之后,电脑B的开始菜单里多了这么几个东东:
点击Putty图标,打开PuTTy configuration窗口,在Hostname里输入电脑A的IP地址,点击Open按钮进行试连接:
结果被踢回来了
再次从电脑B用PuTTy连接电脑A,这次还是被踢回来,只不过错误原因变了:

配置SSH连接秘钥
linux就是这样,软件安装没什么难度,但配置起来头疼事一堆。对我这样的小白非常不友好。之所以出现publickey错误,是因为新版的SSH-2默认使用秘钥认证登陆,也就是说,需要钥匙才行,密码已经落后了。
回到电脑A的Ubuntu命令行窗口,用vi打开SSH服务的配置文件:
# vi /etc/ssh/sshd_config里面有这么一句
# To disable tunneled clear text passwords, change to no here! PasswordAuthentication no
意思是,缺省设置禁止明文密码登陆。将这句改成
# To disable tunneled clear text passwords, change to no here! PasswordAuthentication yes
保存文件,重启ssh服务
# /etc/init.d/ssh restart * Restarting OpenBSD Secure Shell server sshd [ OK ]
再次用PuTTy连接,这次成功了
login as: niuyoucai niuyoucai@localhost's password: Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.4.0-17134-Microsoft x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advanTAGe 1 package can be updated. 0 updates are security updates. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
不过,明文密码太low了吧,怎么也得试试秘钥登陆是不是?这里就不在赘述了,具体可以查看“设置ssh通过密钥登录“
版权声明:本文由“憨小猪”发布,如需转载请注明出处。