For awhile now, each time I got a new Windows laptop I would dig up strasis gist on how to set up agent forwarding for SSH in WSL2 -- but recently I tried to point someone else at it and they were very confused by it, so this is my attempt at simpler instructions.
With Chocolatey, you must use an elevated PowerShell session. If there's no choco
command found, it will fall back to winget for the npiperelay install. To force using Winget even if you have choco installed, you need to download it, so you can pass parameters to it.
Easy mode: just run this in PowerShell:
iex (irm https://gist.githubusercontent.com/Jaykul/19e9f18b8a68f6ab854e338f9b38ca7b/raw/Install.ps1)
To be more cautious, click the Download zip button in the top right, unzip everything, read it through carefully, to make sure I'm not tricking you. Then run the Install.ps1
script from the unzipped files.
It's all designed to be run from PowerShell (5+) on Windows. When commands need to be run in WSL, it will use the wsl
command to do so (as root
and as you). Before you start, make sure you have wsl 2 and a distro installed (run wsl --list -v
and pick a distro that has VERSION 2).
- Install npiperelay in Windows using chocolatey or winget
- Install socat in WSL using apt (sorry, if your distro isn't apt, please fork and comment 😉)
- Copy an
ssh-agent-pipe
script that starts npiperelay for you whenever you open bash - Make that script executable
- Add that script to your .bashrc (note: better not to run this install multiple times 😝)
After some tweaks in the bash script to detect the PID of running process it worked for me. ChatGPT verbose version below:
Logging of all the options: