Thursday | 21 NOV 2024
[ previous ]
[ next ]

Setting Up sshd under WSL2

Title:
Date: 2023-03-25
Tags:  

I want to be able to launch scripts on my windows machine from my server. Something like launching firefox pointed at a URL but driven by server. This requires sshing over to my windows machine, copying over a script and then running that script. This is something wintegrate can do natively but it executes VBS and the emulator itself has those functions baked in.

My method will be to set up ssh on the windows machine and then scp a file over and then use ssh to run the script. Voila! My server can then trigger events on my PC.The first step s install OpenSSH under windows and change the default shell. This way I can use the native ssh server for windows rather than fudge it through wsl2.

Set Up the Windows Side - Powershell

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service -Name sshd -StartupType 'Automatic'
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\System32\bash.exe" -PropertyType String -Force

Set Up WSL2

sudo apt install openssh-server
sudo service sshd start

Update Authorized Keys

Update ~/.ssh/authorized_keys with the public key of the machine you are connecting from.

cat vscode_rsa.pub >> ~/.ssh/authorized_keys

https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machinehttps://nivethan.dev/devlog/notes-on-ssh.html