To use your KeePass (KeeAgent) keys inside WSL Ubuntu without copying the private key files, you need to bridge the communication between the Windows side (where KeeAgent is running) and the Linux side (WSL).
We will use a tool called npiperelay and a utility called socat to forward the SSH "socket" from Windows to Linux.
Note: Your KeePass (KeeAgent) has to be working normally on Windows before you proceed.
First, we need to ensure KeeAgent is exposing the keys via a method npiperelay can understand. The easiest way is to make KeeAgent emulate the Windows OpenSSH agent.
- Open KeePass and go to Tools > KeeAgent Options.
- Check the box: Enable agent for Windows OpenSSH (Create/Use named pipe
\\.\pipe\openssh-ssh-agent).- Note: If this is grayed out, you may need to stop the native Windows OpenSSH Authentication Agent service in Windows Services, but usually, KeeAgent can handle it.
- Click OK.
Open your WSL Ubuntu terminal and install the socket handling tool:
sudo apt update
sudo apt install socatThis is a Windows executable that bridges the connection.
- Go to the npiperelay releases page on GitHub.
- Download the
npiperelay_windows_amd64.zip. - Extract
npiperelay.exe. - Move this file to a location your WSL can access easily. A good practice is to put it in your Windows user folder, or verify you can access it from WSL.
- Example: Let's assume you put it in
C:\tools\npiperelay.exe. - In WSL, this path is accessible at
/mnt/c/tools/npiperelay.exe.
- Example: Let's assume you put it in
You need to tell WSL to create a bridge every time you open a terminal.
-
Edit your configuration file:
nano ~/.bashrc -
Add the following lines to the bottom of the file.
- Important: Replace
/mnt/c/tools/npiperelay.exewith the actual path where you saved the.exefile in Step 3.
# Configure SSH Authentication to bridge to Windows KeeAgent export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock # Check if the socket exists, if not, create the bridge 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:"/mnt/c/tools/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1 fi
- Important: Replace
-
Save and exit (
Ctrl+O,Enter,Ctrl+X). -
Reload the configuration:
source ~/.bashrc
-
Run the following command in WSL to see if it can "see" the keys from KeePass:
ssh-add -l
- Success: You should see the list of fingerprints for the keys currently loaded in KeePass.
- Failure: If it says "Could not open a connection to your authentication agent," check the path to
npiperelay.exein your script.
-
Test the connection to GitHub:
ssh -T git@github.com
You should receive a greeting: "Hi [username]! You've successfully authenticated..."
- WSL (via
socat) creates a Linux socket file (~/.ssh/agent.sock). - When you run
sshin Ubuntu, it sends data to this file. - npiperelay.exe picks up that data and translates it to the Windows "Named Pipe" format.
- KeeAgent receives the request on the Windows side, signs the data using your SSH key, and sends it back.
- Result: Authentication happens without the private key ever leaving the secure KeePass memory on Windows.