Windows 11 OpenSSH agent to WSL2 – addshore
Skip to content
I briefly touched on my OpenSSH agent to WSL2 solution back in 2021. Today find myself setting up a new Windows 11 laptop and running into a couple of different issues, and ultimately using a slightly different solution than before, so here is the short writeup glossing over the areas that lead me to get a little stuck, and hopefully outlining a good set of commands.
In my old .bashrc file, I found a comment linking me to the rupor-github/wsl-ssh-agent GitHub repository which was my first set of reading, specifically the WSL2 compatibility section. The main sticking issue for me out of the box was a miss match in the OpenSSH version between Windows and WSL2, with Windows starting on 8.6 but WSL2 with Ubuntu starting on 8.9. This lead to errors such as:
Error connecting to agent: No such file or directory
error fetching identities: invalid format
Could not open a connection to your authentication agent.
And more…
Setup
The solution still needs npiperelay.exe on the Windows side and socat on WSL to work, so…
I installed npiperelay.exe using Chocolatey from PowerShell
choco install npiperelay
And installed socat on WSL2 from bash.
sudo apt install socat
In order to get the OpenSSH versions to match, I first checked what Ubuntu in WSL2 had shipped with.
adam@adshlb:~$ ssh -v localhost<br>OpenSSH_8.9p1 Ubuntu-3ubuntu0.1, OpenSSL 3.0.2 15 Mar 2022
I want a Windows OpenSSH version that matches, so I checked in Chocolatey for the available versions.
PS C:\Users\adam> winget show Microsoft.OpenSSH.Beta --versions<br>Found OpenSSH Beta [Microsoft.OpenSSH.Beta]<br>Version<br>9.2.2.0<br>9.2.0.0<br>9.1.0.0<br>8.9.1.0Code language: CSS (css)
8.9.1.0 should work with the Ubuntu 8.9 version, so I installed that package using Chocolatey.
winget install Microsoft.OpenSSH.Beta --version 8.9.1.0Code language: CSS (css)
You want to make sure that the Windows SSH agent ends up running automatically on startup, you can check this in the services configuration.
We can then grab the helper script mentioned in the README linked earlier in this post, I have modified this to use the location of npiperelay.exe as installed by Chocolatey for convenience and to avoid the need to edit the file.
wget https://gist.githubusercontent.com/addshore/294a488191529317c16fd2d7e8705a5e/raw/7c71ea90b7252d25603e18da8ee9850f2ead8fe7/wsl-ssh-agent-relay<br>mkdir -P ~/.local/bin<br>mv wsl-ssh-agent-relay ~/.local/bin<br>chmod +x ~/.local/bin/wsl-ssh-agent-relayCode language: JavaScript (javascript)
You should then be able to start the relay with relative ease and set the env var needed for the socket to be used.
${HOME}/.local/bin/wsl-ssh-agent-relay start<br>export SSH_AUTH_SOCK=${HOME}/.ssh/wsl-ssh-agent.sockCode language: JavaScript (javascript)
There is no output (unless you use the -v flag), but you should see the process running.
But in both Windows and WSL2 you should be able to list the keys from your agent, which will initially be empty.
PS C:\Users\adam> ssh-add -L<br>The agent has no identities.
adam@adshlb:~$ ssh-add -L<br>The agent has no identities.
If everything is working, then you’ll want to add the script start command and the setting of the SSH_AUTH_SOCK env var to the bottom of your ~/.bashrc file.
I use KeepassXC for the storage of my SSH keys. There is a whole FAQ section on the SSH key integration if you want to get started. Ultimately you need to create a record with SSH keys attached that request to be loaded into the agent. And in the KeepassXC settings, you need to enable SSH Agent integration and select "Use OpenSSH"
This should then load your keys into the Windows agent when your vault is unlocked, and this should pipe through to the WSL agent, making all keys accessible in both Windows and WSL2 when your vault is unlocked. Also removing them when it is locked.
Share this:
Share on Facebook (Opens in new window)<br>Facebook
Share on X (Opens in new window)
Share on LinkedIn (Opens in new window)<br>LinkedIn
Share on Reddit (Opens in new window)<br>Reddit
Email a link to a friend (Opens in new window)<br>Email
Share on Telegram (Opens in new window)<br>Telegram
Share on WhatsApp (Opens in new window)<br>WhatsApp
Like this:<br>Like Loading…
Related
1 thought on “Windows 11 OpenSSH agent to WSL2”
Pingback: Bitwarden ssh-agent on WSL2 - rebelpeon.com
Leave a CommentCancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Tags
agent<br>ai<br>API<br>commons<br>docker<br>event<br>for-wmde<br>git<br>GitHub<br>github copilot<br>go<br>golang<br>google<br>google cloud<br>grafana<br>Hackathon<br>Java<br>kubernetes<br>map<br>MediaWiki<br>PHP<br>Presentation<br>query<br>query service<br>sailinghannahpenn<br>sparql<br>traveling<br>twitter<br>visualization<br>wbstack<br>wdqs<br>wikibase<br>wikibase-docker<br>wikibase.cloud<br>wikibase.world<br>Wikidata<br>wikidata query service<br>Wikimedia<br>Wikipedia<br>Windows<br>wmde<br>wordpress<br>wsl<br>WSL2<br>year review
Latest Posts
Overlap Atlas (Android timeline overlaps)
Eero Pro 6 teardown
Dartmoor camping related map data...