Skip to content

Instantly share code, notes, and snippets.

@matthiasr
Last active September 25, 2025 11:32
Show Gist options
  • Save matthiasr/473072eeffe449459e3ccd0f5192afc7 to your computer and use it in GitHub Desktop.
Save matthiasr/473072eeffe449459e3ccd0f5192afc7 to your computer and use it in GitHub Desktop.

Revisions

  1. matthiasr revised this gist Feb 10, 2023. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions gpg_wsl2.md
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,12 @@ Notably, when using a TTY-based pinentry, signing in Visual Studio Code does not

    1. Install [Gpg4Win](https://www.gpg4win.org/): `winget install -e GnuPG.Gpg4win` or download and install manually
    2. Start Kleopatra and generate or import keys
    3. Insert a link to `gpg.exe` inside of WSL: `sudo ln -s /mnt/c/Program\ Files\ \(x86\)/GnuPG/bin/gpg.exe /usr/local/bin/gpg`
    4. That's it! Git and other GPG commands will now use the GPG installed in Windows, which has access to the GPG agent from Gpg4Win, and uses its graphical pinentry for passphrases.
    3. Insert links to `gpg.exe` inside of WSL:
    ```
    sudo ln -s /mnt/c/Program\ Files\ \(x86\)/GnuPG/bin/gpg.exe /usr/local/bin/gpg
    sudo ln -s gpg /usr/local/bin/gpg2
    ```
    5. That's it! Git and other GPG commands will now use the GPG installed in Windows, which has access to the GPG agent from Gpg4Win, and uses its graphical pinentry for passphrases.
    # Troubleshooting
  2. matthiasr revised this gist Feb 3, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gpg_wsl2.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Notably, when using a TTY-based pinentry, signing in Visual Studio Code does not

    # Troubleshooting

    This `gpg` should` take precedence over any gpg installed on the system. Verify this with `command -v gpg`.
    This `gpg` should take precedence over any gpg installed on the system. Verify this with `command -v gpg`.
    If this is not `/usr/local/bin/gpg`, check `$PATH` for the order of precedence on your system, and create the link in a directory that precedes (is left of) `/usr/bin` or wherever the package manager installed GPG.

    # See also
  3. matthiasr revised this gist Feb 3, 2023. No changes.
  4. matthiasr created this gist Feb 3, 2023.
    21 changes: 21 additions & 0 deletions gpg_wsl2.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # Problem statement

    Signing with GPG in Windows System for Linux (WSL2) does not work smoothly out of the box.
    Notably, when using a TTY-based pinentry, signing in Visual Studio Code does not work at all.

    # Solution

    1. Install [Gpg4Win](https://www.gpg4win.org/): `winget install -e GnuPG.Gpg4win` or download and install manually
    2. Start Kleopatra and generate or import keys
    3. Insert a link to `gpg.exe` inside of WSL: `sudo ln -s /mnt/c/Program\ Files\ \(x86\)/GnuPG/bin/gpg.exe /usr/local/bin/gpg`
    4. That's it! Git and other GPG commands will now use the GPG installed in Windows, which has access to the GPG agent from Gpg4Win, and uses its graphical pinentry for passphrases.

    # Troubleshooting

    This `gpg` should` take precedence over any gpg installed on the system. Verify this with `command -v gpg`.
    If this is not `/usr/local/bin/gpg`, check `$PATH` for the order of precedence on your system, and create the link in a directory that precedes (is left of) `/usr/bin` or wherever the package manager installed GPG.

    # See also

    * [wsl2-gpg-agent](https://github.com/AkashiSN/wsl2-gpg-agent)
    * [SSH access to 1Password](https://dev.to/d4vsanchez/use-1password-ssh-agent-in-wsl-2j6m)