JohnLyu的blog

橙汁事务所艾欧泽亚分部

0%

在WSL启用ssh-server并且开机启动

最好的Linux发行版是Windows10!

以下内容仅适用于Debian/Ubuntu.

安装并启动sshd

首先, 需要在发行版中确认存在openssh-server这个包.
和正常发行版不同的是, wsl中并没有使用systemd来启动系统.War, war never changes
因此, 想要启动ssh-server必须通过/etc/init.d/ssh来实现.

注意此处要修改/etc/ssh/sshd_config. 其中的Port建议修改为大于1024的端口, PasswordAuthentication建议修改为yes.

测试/etc/init.d/ssh start, 成功后进行下一步.

开机自启动sshd

wsl在执行第一个命令之前不会启动, 因此, 我们需要编写一个start_sshd.vbs脚本, 添加到计划任务里的开机启动事件.

脚本内容为:

1
2
3
Set wshell=wscript.createobject("wscript.shell")
wshell.run "C:\Windows\System32\wsl.exe sudo /etc/init.d/ssh start",0
Set wshell=Nothing

然而sudo命令需要输入密码才能启动, 为了bypass这一点, 需要修改sudo文件.

1
sudo visudo

添加

1
2
# for wsl start sshd
%sudo ALL=NOPASSWD: /etc/init.d/ssh start

并保存.

完成后请务必重启系统测试.