I want to launch an SSH server on Linux subsystem (Bash on Ubuntu on Windows) at windows startup. The problem is that all Linux processes are terminated when Bash window is closed.
Is there a way to make Linux process run permanently in background without bash window?
Answer
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 theUsePrivilegeSeparation yes
line to readUsePrivilegeSeparation no
. (This is necessary becauseUsePrivilegeSeparation
uses thechroot()
syscall, which WSL doesn't currently support.) - While still editing
/etc/ssh/sshd_config
, you may choose to changePasswordAuthentication no
toPasswordAuthentication 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. Usewscript.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!
No comments:
Post a Comment