Skip to content

Instantly share code, notes, and snippets.

@ChristianGrimberg
Last active July 10, 2025 15:47
Show Gist options
  • Select an option

  • Save ChristianGrimberg/1f05e6786e73f1e99604cc61d1fc09a3 to your computer and use it in GitHub Desktop.

Select an option

Save ChristianGrimberg/1f05e6786e73f1e99604cc61d1fc09a3 to your computer and use it in GitHub Desktop.
Sharing GPG Key and Configuration Agent in Windows to WSL and Visual Studio Dev Containers
# enable GPG signing
export GPG_TTY=$(tty)
if [ ! -f ~/.gnupg/S.gpg-agent ]; then
eval $( gpg-agent --daemon --options ~/.gnupg/gpg-agent.conf &>/dev/null )
fi
export GPG_AGENT_INFO=${HOME}/.gnupg/S.gpg-agent:0:1

Sharing GPG Key and Configuration Agent in Windows to WSL and Visual Studio Dev Containers

After configuring the GPG Key with Git Bash program from Windows, you can do this to sharing the same configuration to WSL2 and Visual Studio Dev Containers.

Transfer GPG Configuration Folder from Git Bash to Windows Roaming Data and WSL2 Distro

  1. In Windows, copy all the content from ~/.gnupg to clipboard.
  2. In Windows, paste this content to ~/AppData/Roaming/gnupg from the clipboard.
  3. In the distro from WSL2, paste this content to \\wsl.localhost\{distribution}\home\{username}\.gnupg from the clipboard.

Setting GPG Agent in WSL2 on Windows 10/11

  1. In the distro from WSL2, copy from the file .bashrc to add this lines al the end of file \\wsl.localhost\{distribution}\home\{username}\.bashrc.
  2. Run this command from Linux Distribution in WSL2 and copy the GPG ID: gpg --list-secret-keys --keyid-format LONG.
  3. In the distro from WSL2, copy from the file gpg.conf to adding this to file path \\wsl.localhost\{distribution}\home\{username}\.gnupg\gpg.conf. Then insert the GPG ID Key into the file.
  4. In the distro from WSL2, copy from the file gpg-agent.conf to adding this to file path \\wsl.localhost\{distribution}\home\{username}\.gnupg\gpg-agent.conf.
default-cache-ttl 34560000
max-cache-ttl 34560000
pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"
# Uncomment within config (or add this line)
# This tells gpg to use the gpg-agent
use-agent
# Set the default key
default-key {insert gpg key id}
@garrytrinder
Copy link

Thank you for documenting this @ChristianGrimberg 👏

It worked perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment