-
-
Save shinji257/3e18b3e9254e69ebbfbe92ea7128a8ff to your computer and use it in GitHub Desktop.
WSL2 gpg agent relay (Yubikey)
This file contains 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 | |
# Launches socat+npiperelay to relay the gpg-agent socket file for use in WSL | |
# See https://justyn.io/blog/using-a-yubikey-for-gpg-in-windows-10-wsl-windows-subsystem-for-linux/ for details | |
GPGDIR="${HOME}/.gnupg" | |
USERNAME=Vincent | |
# I use the same username for wsl and windows, but feel free to modify the paths below if that isn't the case | |
WIN_GPGDIR="C:/Users/${USERNAME}/AppData/Roaming/gnupg" | |
NPIPERELAY="${HOME}/npiperelay.exe" | |
PIDFILE="${GPGDIR}/.gpg-agent-relay.pid" | |
OLDPID=$(cat "${PIDFILE}") | |
if [ ! -z "${OLDPID}" ]; then | |
ps -p "${OLDPID}" >/dev/null && exit 0 | |
fi | |
rm -f "${GPGDIR}/S.gpg-agent" "${GPGDIR}/S.gpg-agent.ssh" | |
# Relay the regular gpg-agent socket for gpg operations | |
socat UNIX-LISTEN:"${GPGDIR}/S.gpg-agent,fork" EXEC:"${NPIPERELAY} -ep -ei -s -a '${WIN_GPGDIR}/S.gpg-agent'",nofork & | |
AGENTPID=$! | |
# Relay the gpg ssh-agent | |
socat UNIX-LISTEN:"${GPGDIR}/S.gpg-agent.ssh,fork" EXEC:"${NPIPERELAY} -ep -ei -s -a '${WIN_GPGDIR}/S.gpg-agent.ssh'",nofork & | |
SSHPID=$! | |
echo $AGENTPID > ${PIDFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment