Last active
January 25, 2026 08:59
-
-
Save sevkin/0ed684d7c5d1d89605b1ea506191a016 to your computer and use it in GitHub Desktop.
use windows pageant keys inside wsl2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # use windows pageant keys inside wsl2 | |
| # | |
| # call me from .bashrc on wsl | |
| # on windows host: | |
| # shell:startup => "C:\Program Files\PuTTY\pageant.exe" --openssh-config %USERPROFILE%\.ssh\pageant.conf "C:\path\to\putty\key.ppk" | |
| # | |
| # %USERPROFILE%\.ssh\config contains all need hosts for ssh and vscode | |
| # Include pageant.conf | |
| # | |
| # Host alias | |
| # HostName ip-or-domain | |
| # User username | |
| # ... | |
| # | |
| # https://github.com/rupor-github/wsl-ssh-agent/releases/download/v1.6.9/wsl-ssh-agent.zip -> %USERPROFILE%/.local/bin/npiperelay.exe | |
| # on wsl: | |
| # apt install wslu ; for wslvar | |
| SSH_AUTH_SOCK="$HOME/.ssh/agent.sock" | |
| # Exit if socket already exists and is a valid socket | |
| if ss -a | grep -q "$SSH_AUTH_SOCK"; then | |
| return | |
| fi | |
| # Remove stale socket | |
| rm -f "$SSH_AUTH_SOCK" | |
| USER_PROFILE="$(wslpath $(wslvar USERPROFILE))" | |
| PAGEANT_CONF="$USER_PROFILE/.ssh/pageant.conf" | |
| NPIPERELAY="$USER_PROFILE/.local/bin/npiperelay.exe" | |
| PAGEANT_PIPE=$(cat $PAGEANT_CONF | sed 1q | cut -d'"' -f2) | |
| # copy config from windows host | |
| cat $USER_PROFILE/.ssh/config \ | |
| | sed "s#Include pageant.conf#IdentityAgent \"$SSH_AUTH_SOCK\"#" \ | |
| > $HOME/.ssh/config | |
| # Start socat/npiperelay as a background process | |
| setsid socat \ | |
| UNIX-LISTEN:"$SSH_AUTH_SOCK",unlink-close,unlink-early,fork \ | |
| EXEC:"$NPIPERELAY -ei -s $PAGEANT_PIPE",nofork \ | |
| >/dev/null 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment