This configures a systemd based WSL instance such as Ubuntu to use the Windows SSH key agent service or any compatible SSH key agent running under Windows such as Keepass KeeAgent or Putty pageant.
Requires npiperelay.exe. Can be istalled manually, via wininstall or chocolatey
Requires a OpenSSH compatible SSH key agent running on Windows. Either ssh-agent from Windows OpenSSSH, Putty Pageant, Keepass kagent, or any other OpenSSH compatible key agent.
Note: Windows bundled ssh-agent prior to version 8.9 will fail if your WSL is using OpenSSL 8.9 or later. Upgrade your wWindows SSH to a later OpenSSH version using 'winget install "openssh beta"'. Use "ssh -V" from a cmd window to check your version. Or use another OpenSSH compatible Windows SSH Key agent.
Install by running 'make'
Clean up .config/systemd/ and your .bashrc
There is four parts that makes this work
- npiperelay.exe (windows side) enables connection to Windows pipes via WSL command pipes.
- ssh-auth.socket systemd socket creates a listening UNIX pipe on the WSL side
- [email protected] systemd service starts npiperelay.exe when an application (ssh or similar) connects to the UNIX pipe
- ssh-auth.bashrc sets SSH_AUTH_SOCK pointing to the above UNIX pipe, enabling ssh to find the ssh-agend connection
- windows SSH key agent listens for local connections on //./pipe/openssh-ssh-agent
- ssh connects to the listening socket set up by systemd (/run/user/<uid>/ssh-auth-sock)
- systemd starts npiperelay.exe, connecting to the WSL unix pipe socket to the Windows side pipe //./pipe/openssh-ssh-agent
Inspired by the blog post Use an ssh-agent in WSL with your ssh setup from windows 10
For WSL1 instances there is wsl-ssh-agent.
Pageant must be started with the --openssh-config command line argument.
pageant --openssh-config %USERPROFILE%\.ssh\pageant.conf
Note: You can also automate loading of keys by listing the keys on the command line
Create a custom shortcut in the autostart folder (Win-R shell:startup) to have pageant launched with the right options when you login