nerd space
  1. How to use KeepassXC to serve SSH keys to WSL2 and Ubuntu
    1. Setup
14 September 2022

How to use KeepassXC to serve SSH keys to WSL2 and Ubuntu

I am back on windows and I don’t want to spin up linux VMs to do file editing stuff. In linux I use KeepassXC which has a windows client so I thought there might be a solution that can allow me to use KeepassXC and WSL2 and boom found a solution.

Read more about it here by Mendhak but he is using Npiperelay and socat to do all the magic.

Keeagent with wsl by Mendhak.


Npiperelay allows named pipes to communicate between Linux in WSL and Windows.

# run this inside WSL2
cd ~ && wget
unzip -d npiperelay && rm

Socat allows WSL2 to communicate with Npiperelay.

# install socat
sudo apt install socat
# place this inside your .bashrc
#  Socat and npiperelay for KeepassXC SSH and WSL2

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:"$HOME/npiperelay/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1

Now you are done.

Do make sure to set OpenSSH Authentication Agent service Start type to Automatic. Also make sure to Enable SSH Agent intergration and set Use OpenSSH in KeePassXC -> Tools -> Settings -> SSH Agent.