Hook into Windows' SSH Agent under WSL

This will securely store SSH key in the host system, tied to your user
account, will be locked when Windows is locked, and will avoid having to
type SSH passphrase in every new window you open.
Bo Jeanes 2020-04-03 20:32:11 +11:00
parent 0444b73bd5
commit c77820e856
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
if [ -n ${WSL_DISTRO_NAME:-} ] || grep -sqi microsoft /proc/sys/kernel/osrelease; then
# # Talk to Windows' SSH-Agent when under WSL, using https://github.com/rupor-github/wsl-ssh-agent
# # wsl-ssh-agent started with:
# #
# # wsl-ssh-agent-gui.exe -setenv -envname=WSL_AUTH_SOCK -lemonade=2489;127.0.0.1/24
# #
# [ -n ${WSL_AUTH_SOCK} ] && export SSH_AUTH_SOCK=${WSL_AUTH_SOCK}
# Above does not work currently due to WSL1 -> WSL2 turbulence. Workaround below.
# Based on: https://github.com/rupor-github/wsl-ssh-agent/tree/4e08e3fa84380f4d62bfdf607ae6b2c680e1ff3e#wsl-2-compatibility
# where I installed it (must be on Windows' filesystem)
NPIPERELAY_DIR="/mnt/c/Program Files/WSL-SSH-Agent"
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0 ]; then
rm -f $SSH_AUTH_SOCK
(
PATH="$NPIPERELAY_DIR:$PATH"
setsid socat \
UNIX-LISTEN:$SSH_AUTH_SOCK,fork \
EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &
) >/dev/null 2>&1
fi
fi