1

I installed GPG4Win and Kleopatra on my Windows 10 system, and imported my public and private key files that were created on another machine. My goal is to sign my commits in Github using these keys (which I've done in the past from the old machine). After I import the keys, I run this command in the Windows command line or Powershell, and it shows the keys:

C:\Users\michael>gpg --list-keys
C:\Users\michael\AppData\Roaming\gnupg\pubring.kbx
---------------------------------------------
pub   rsa4096 2020-01-14 [SC]
      <snipped the fingerprint>
uid           [ultimate] Michael (Github) <[email protected]>
sub   rsa4096 2020-01-14 [E]

However, when I run these commands in git bash (restarting git bash after the first one), nothing is displayed:

$ git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
$ gpg --list-secret-keys
$ gpg --list-keys

Why do the keys show up in the Windows command line, but not git bash (even after setting the GPG program correctly)? My guess is that it's still something to do with the path but I thought setting the global git setting would fix that.

2
  • I'd guess that GPG relies on a daemon and environment variables to find it. Maybe Git Bash cannot find it?
    – Daniel B
    Commented Feb 20, 2022 at 19:33
  • @DanielB How would I verify this?
    – Michael A
    Commented Feb 20, 2022 at 20:06

3 Answers 3

2

@avraham Suggestion helped with forcing GPG to use the GPG4WIN directory, however, git itself was still using its own gpg binary stored in which was unable to read my GPG4WIN GPG repository.

In order to force git bash to use GPGWIN's version, I had to rewrite the PATH variable using .bash_profile to prioritize the folder search order so the GPG4WIN folder was searched first. (By default git bash uses in it's version of gpg, C:\Program Files\Git\usr\bin\gpg.exe because it's folders are higher in the path configuration.)

Before the rewrite of the path variable, git's own paths were listed before any inherited paths from Windows' environment variables:

$ where gpg
C:\Program Files\Git\usr\bin\gpg.exe
C:\Program Files (x86)\GnuPG\bin\gpg.exe

After writing the following .bash_profile file in my home directory:

$ cat .bash_profile
# Custom configuration file to force GIT bash to use GPG from GPG4WIN
export PATH=/c/PROGRA~2/GnuPG/bin:/c/Users/ez/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin

NOTE: I'm using the short name for 'Program Files (x86)' to avoid any interpretation problems by bash.

After this, I sourced .bash_profile and finally, git bash used the GPG4WIN version of gpg from the command line. To verify this worked, run where gpg again:

$ where gpg
C:\Program Files (x86)\GnuPG\bin\gpg.exe
C:\Program Files\Git\usr\bin\gpg.exe
1
  • setting up the PATH in bash_profile resolved my issuse. Thanks!
    – DineshKP
    Commented Jun 27 at 5:42
1

I had the same issue. By me, the problem was that somehow, my installed version of GPG4WIN knew to look somewhere else other than the default home/.gnupg folder for my "real" kbx. You can see this by calling gpg --version in CMD and in Rstudio/Git bash. Look at the first line after the warranty disclaimer; it starts with "Home". Your git version will be the default; your CMD version (which shows your keys) will be something like C:\Users\USERNAME\AppData\Roaming\gnupg. What you can do is create an enviornment variable called GNUPGHOME and set it to the location of your true home. This will override any other setting and when you next call gpg from within bash, it should find your keys.

0

In my case, install Git Bash will also install gpg in path C:\Program Files\Git\usr\bin\gpg.exe, and I install GPG4Win and Kleopatra too.

On Bash, I run where gpg, get both path C:\Program Files\Git\usr\bin\gpg.exe C:\Program Files (x86)\GnuPG\bin\gpg.exe

On CMD, I run where gpg, get C:\Program Files (x86)\GnuPG\bin\gpg.exe

On PowerShell, I run (get-command gpg.exe).Path, get C:\Program Files (x86)\Gpg4win\..\GnuPG\bin\gpg.exe

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .