How to run Ubuntu service on Windows (at startup)?
發表於 : 2019-02-18 17:06:48
https://superuser.com/questions/1112007 ... at-startup
22
Found a tutorial for that by aseering:
This was originally discussed and sorted out by github users imjakey, fpqc, qris, therealkenc, Manouchehri, and aseering (myself) here:
https://github.com/Microsoft/BashOnWindows/issues/612
Note that running sshd has security implications. Until WSL's security model has had longer to bake, you should assume that anyone who can ssh into your Windows box has permission to perform any command as the Windows user running sshd, regardless of Linux-level permissions. (Permissions are probably more restrictive than that in practice, but WSL's initial security model is not intended to be very sophisticated.)
Attempting to aggregate the instructions from github:
Generate SSH host keys by running sudo dpkg-reconfigure
openssh-server in a bash shell
Run sudo nano /etc/ssh/sshd_config; edit the UsePrivilegeSeparation yes line to read UsePrivilegeSeparation no. (This is necessary because UsePrivilegeSeparation uses the chroot() syscall, which WSL doesn't currently support.)
While still editing /etc/ssh/sshd_config, you may choose to change PasswordAuthentication no to PasswordAuthentication yes. Otherwise you will have to set up SSH keys.
Save /etc/ssh/sshd_config and exit.
Run sudo visudo to edit the sudoers file. Add the line
$USER ALL = (root) NOPASSWD: /usr/sbin/sshd -D
replacing "$USER" with your Linux username. Save and exit. If visudo complains that your changes are invalid, fix them until it reports that they are valid; otherwise you can break sudo on your system!
On the Windows side, edit the Windows firewall (and any third-party firewalls that you might be running) to allow incoming traffic on port 22. Because this isn't a super-secure setup, I recommend only allowing incoming traffic from home (private) and domain networks, not from the public Internet.
Create a text file autostartssh.vbs in Windows containing the following:
set ws=wscript.createobject("wscript.shell")
ws.run "C:\Windows\System32\bash.exe -c 'sudo /usr/sbin/sshd -D'",0
Double-click on the script. It should start sshd; you should be able to ssh into your Windows machine.
Open Windows's Task Scheduler. Add a task that runs autostartssh.vbs on system boot. Use wscript.exe as the command to run and the VBS script location as the parameter.
And that's it -- your Windows computer should be running a Linux openssh server!
22
Found a tutorial for that by aseering:
This was originally discussed and sorted out by github users imjakey, fpqc, qris, therealkenc, Manouchehri, and aseering (myself) here:
https://github.com/Microsoft/BashOnWindows/issues/612
Note that running sshd has security implications. Until WSL's security model has had longer to bake, you should assume that anyone who can ssh into your Windows box has permission to perform any command as the Windows user running sshd, regardless of Linux-level permissions. (Permissions are probably more restrictive than that in practice, but WSL's initial security model is not intended to be very sophisticated.)
Attempting to aggregate the instructions from github:
Generate SSH host keys by running sudo dpkg-reconfigure
openssh-server in a bash shell
Run sudo nano /etc/ssh/sshd_config; edit the UsePrivilegeSeparation yes line to read UsePrivilegeSeparation no. (This is necessary because UsePrivilegeSeparation uses the chroot() syscall, which WSL doesn't currently support.)
While still editing /etc/ssh/sshd_config, you may choose to change PasswordAuthentication no to PasswordAuthentication yes. Otherwise you will have to set up SSH keys.
Save /etc/ssh/sshd_config and exit.
Run sudo visudo to edit the sudoers file. Add the line
$USER ALL = (root) NOPASSWD: /usr/sbin/sshd -D
replacing "$USER" with your Linux username. Save and exit. If visudo complains that your changes are invalid, fix them until it reports that they are valid; otherwise you can break sudo on your system!
On the Windows side, edit the Windows firewall (and any third-party firewalls that you might be running) to allow incoming traffic on port 22. Because this isn't a super-secure setup, I recommend only allowing incoming traffic from home (private) and domain networks, not from the public Internet.
Create a text file autostartssh.vbs in Windows containing the following:
set ws=wscript.createobject("wscript.shell")
ws.run "C:\Windows\System32\bash.exe -c 'sudo /usr/sbin/sshd -D'",0
Double-click on the script. It should start sshd; you should be able to ssh into your Windows machine.
Open Windows's Task Scheduler. Add a task that runs autostartssh.vbs on system boot. Use wscript.exe as the command to run and the VBS script location as the parameter.
And that's it -- your Windows computer should be running a Linux openssh server!