Skip to content

Setup systemd based WSL instances to use the Windows SSH agent

Notifications You must be signed in to change notification settings

hno-addiva/wsl-ssh-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose

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.

Requirements

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.

Installation

Install by running 'make'

Uninstallation

Clean up .config/systemd/ and your .bashrc

Theory of operation

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
  1. windows SSH key agent listens for local connections on //./pipe/openssh-ssh-agent
  2. ssh connects to the listening socket set up by systemd (/run/user/<uid>/ssh-auth-sock)
  3. systemd starts npiperelay.exe, connecting to the WSL unix pipe socket to the Windows side pipe //./pipe/openssh-ssh-agent

Related work

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.

Using Putty Pageant

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

About

Setup systemd based WSL instances to use the Windows SSH agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published