Skip to content

Instantly share code, notes, and snippets.

@blackthornedk
Last active March 3, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackthornedk/78b0c6c4b0f2a95fb3309d4fee35609f to your computer and use it in GitHub Desktop.
Save blackthornedk/78b0c6c4b0f2a95fb3309d4fee35609f to your computer and use it in GitHub Desktop.
WSL SSH Agent Setup

Packages needed in WSL:

  • tmux
  • socat

Files needed in Windows:

Put wsl-ssh-pageant.exe and npiperelay.exe in %UserProfile%\bin

In %appdata%\Microsoft\Windows\Start Menu\Programs\Start\

Shortcut: %UserProfile%\bin\wsl-ssh-pageant.exe -systray --winssh ssh-agent

IF KeeAgent is used:

The named pipe can be enabled in KeeAgent settings, which makes wsl-ssh-pageant unnecessary. https://keepass.info/plugins.html#keeagent

In .bashrc

if [ ! -S /tmp/wsl-auth-sock ] && [ -z "$TMUX" ] && [ ! $(pgrep socat) ]; then
        echo "Starting socat relay to ssh-pageant"
        tmux new-session -d -s socat-ssh-agent
        tmux send-keys '/usr/bin/socat UNIX-LISTEN:/tmp/wsl-auth-sock,fork EXEC:"/mnt/c/Users/$USER/bin/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork' C-m
fi

check_auth_socket() {
        powershell.exe "[System.IO.Directory]::GetFiles(\"\\\\.\\\\pipe\\\\\") | Select-String \"agent\""
}

export SSH_AUTH_SOCK=/tmp/wsl-auth-sock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment