Since I’m using the Windows ssh-agent, I’d like to make that available to wsl things too.
You do that by listening on the ssl agent socket in Linux, and forwarding those to a proxy program in Windows, which contacts the agent.
In Windows
You need a program called npiperelay:
winget install albertony.npiperelay
Restart powershell and display your path to see where npiperelay got installed. You’ll need that path in the next step.
$env:Path
That’s all: this will be invoked from inside Linux.
In Linux
We are going to set it up so that a new socat process is launched
every time something tries to connect to the agent socket.
I originally had it as a single long-running process,
but for reasons I didn’t look into,
it stopped working after a day or two.
This way is a little slower,
but it should get a “fresh” connection every time.
You’ll need two new systemd config files:
~/.config/systemd/user/ssh-agent.socket
[Unit]
Description=OpenSSH Agent socket relay to Windows
[Socket]
SocketMode=0600
ListenStream=%t/ssh-agent.socket
Accept=yes
Service=ssh-agent@.service
ExecStartPost=/usr/bin/systemctl --user set-environment SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStopPre=/usr/bin/systemctl --user unset-environment SSH_AUTH_SOCK
[Install]
WantedBy=sockets.target
~/.config/systemd/user/ssh-agent@.service
[Unit]
Description=OpenSSH Agent relay to Windows
Requires=ssh-agent.socket
[Service]
Type=simple
StandardInput=socket
StandardOutput=socket
StandardError=journal
ExecStart=/usr/bin/socat - EXEC:"/mnt/c/Users/pick167/AppData/Local/Microsoft/WinGet/Packages/albertony.npiperelay_Microsoft.Winget.Source_8wekyb3d8bbwe/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork
Restart=no
KillMode=process
I don’t know what 8wekyb3d8bbwe means here,
but it’s probably going to be something different on your Windows install.
Be sure to substitute in the path where npiperelay installed:
it will be in the Path you got from PowerShell.
Enable the socket
In the shell:
systemctl --user daemon-reload
systemctl --user enable --now ssh-agent.socket
Finalize
Close your wsl window and open it again to get the new environment variables, then list your keys!
ssh-add -l
If it stops working
The first thing I would check is the journal logs:
journalctl --user
If you’re seeing something about the executable not being found,
it may be that an update to npiperelay changed the path.
Go into PowerShell and get the path again,
then check that against what’s in ssh-agent@.service.