2023-04-18 Run SSH on WSL2 Tags: wsl sshThe goal is to share the Windows OpenSSH service located in `C:\Windows\System32\OpenSSH` to WSL2. Adapted from: https://github.com/rupor-github/wsl-ssh-agent#wsl-2-compatibility Build npiperelay in Windows: ``` winget install GoLang.Go go install -v -x github.com/jstarks/npiperelay@v0.1.0 ``` Link it from WSL + install socat: ``` sudo ln -s /mnt/c/Users/tomas/go/bin/npiperelay.exe /usr/local/bin/npiperelay.exe sudo apt install socat mkdir ~/.ssh chmod 700 ~/.ssh ``` Add the following to `.bashrc`: ```bash export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock ss -a | grep -q $SSH_AUTH_SOCK if [ $? -ne 0 ]; then rm -f $SSH_AUTH_SOCK ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1 fi ``` ### Update for Ubuntu 22.04 images The Windows supplied OpenSSH is old and incompatible, have to switch to the one from https://scoop.sh/ ``` scoop install openssh ``` Then change the ssh-agent Windows service to launch the correct version, in regedit open: `Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\ssh-agent` and change `ImagePath` to `C:\Users\tomas\scoop\shims\ssh-agent.exe` + Add `C:\Users\tomas\scoop\shims` to User PATH - Remove `%SystemRoot%\System32\OpenSSH` from System PATH