当前位置:首页 > 其他 > windows > Windows 10内置Ubuntu子系统安装SSH服务

Windows 10内置Ubuntu子系统安装SSH服务

DChen3年前 (2021-04-21)windows1.26 K0

第一步,打开Ubuntu命令行窗口,切换到root用户,安装tasksel程序并执行:

# apt install tasksel -y
# tasksel

出现下面这个紫色的小窗口:1.png Windows 10内置Ubuntu子系统安装SSH服务  linux ssh 第1张

在列表底部空格键选择Openssh server(注意先用空格取消默认的几个选择),Tab键把光标切到OK按钮上,回车,等待自动安装结束,重新回到命令行,SSH服务器就装好了。
看着很简单,试着启动一下就出错了。
# /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的开始菜单里多了这么几个东东:

2.png Windows 10内置Ubuntu子系统安装SSH服务  linux ssh 第2张

点击Putty图标,打开PuTTy configuration窗口,在Hostname里输入电脑A的IP地址,点击Open按钮进行试连接:

3.png Windows 10内置Ubuntu子系统安装SSH服务  linux ssh 第3张

结果被踢回来了

4.png Windows 10内置Ubuntu子系统安装SSH服务  linux ssh 第4张


这才想起电脑A的22端口没打开,当然拒绝访问了。只需进入电脑A的控制面板->系统和安全->Windows Defender防火墙->高级设置,点击“入站规则->新建规则”,开放22端口,重启电脑A。
再次从电脑B用PuTTy连接电脑A,这次还是被踢回来,只不过错误原因变了:
5.png Windows 10内置Ubuntu子系统安装SSH服务  linux ssh 第5张

配置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通过密钥登录



取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

版权声明:本文由“憨小猪”发布,如需转载请注明出处。

本文链接:https://www.phper.red/post/60.html

标签: linuxssh

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。