Skip to content

Instantly share code, notes, and snippets.

@caneko
Forked from dentechy/WSL-ssh-server.md
Last active February 2, 2024 15:45
Show Gist options
  • Save caneko/21b36f0504600d98a7370c4955bc559f to your computer and use it in GitHub Desktop.
Save caneko/21b36f0504600d98a7370c4955bc559f to your computer and use it in GitHub Desktop.
A step by step tutorial on how to automatically start ssh server on boot on the Windows Subsystem for Linux

Setup ssh for WSL

Original gist from dentechy/WSL-ssh-server.md

For ArchWSL

Link

Setup ssh

sudo pacman -S openssh
sudo ssh-keygen -A
sudo vim /etc/ssh/sshd_config

add

Port 22
PasswordAuthentication yes
Hostkey /etc/ssh/ssh_host_dsa_key
Hostkey /etc/ssh/ssh_host_ecdsa_key
Hostkey /etc/ssh/ssh_host_ed25519_key
Hostkey /etc/ssh/ssh_host_rsa_key

Auto start from Windows

cd /tmp
echo 'C:\Windows\System32\bash.exe -c "sudo /usr/sbin/sshd -D"' > sshd.bat
mv sshd.bat /mnt/c/sshd.bat
vim sshd.vbs
  • Add the following code, making sure to put in your actual user name:
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\sshd.bat" & Chr(34), 0
Set WinScriptHost = Nothing

mv ./sshd.vbs /mnt/c/sshd.vbs

  • Open start menu, type run. Then type shell:startup. Copy the vbs file over to the Startup folder

vim /etc/sudoers add at the bottom %sudo ALL=NOPASSWD: /usr/sbin/sshd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment