Skip to content

Instantly share code, notes, and snippets.

@invalidusrname
Last active January 10, 2023 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invalidusrname/d6c36d1eea234907e8ad2309e7209e2a to your computer and use it in GitHub Desktop.
Save invalidusrname/d6c36d1eea234907e8ad2309e7209e2a to your computer and use it in GitHub Desktop.
GPG trouble signing git commits
$ GIT_TRACE=1 git commit -a -S -m 'whitespace'
10:21:20.904618 git.c:415 trace: built-in: git commit -a -S -m whitespace
10:21:20.907237 run-command.c:637 trace: run_command: gpg --status-fd=2 -bsau E288164435BD1457
error: gpg failed to sign the data
fatal: failed to write commit object
$ gpg --status-fd=2 -bsau E288164435BD1457
[GNUPG:] KEY_CONSIDERED 02FE60A5E2F61054A2159661E288164435BD1457 2
[GNUPG:] BEGIN_SIGNING H8
^C
gpg: signal Interrupt caught ... exiting
$ gpg --version
gpg (GnuPG) 2.2.15
libgcrypt 1.8.4
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Home: /Users/mmcmahand/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
$ git --version
git version 2.19.1
#!/bin/sh
brew install pinentry-mac
# echo hello world | gpg2 -e -r YOUR_KEY_ID | gpg2 -d
echo hello world | gpg2 -e -r 930A13C1 | gpg2 -d
@invalidusrname
Copy link
Author

I found that adding GPG_TTY=$(tty) will prompt in the shell for my password. So that works, but it's dumb

@invalidusrname
Copy link
Author

Update: I figured it out by installing pinentry

@M-Dominguez
Copy link

Yes, you need to tell gpg where your tty lives in order for it to prompt you for the password. usually this is done in the your ~/.bashrc file. You can append export GPG_TTY=$(tty) to the end of the file and the source it source ~/.bashrc to automatically tell gpg where you tty is every time you open your terminal.

NOTE: if you are using a different shell like ZSH then you will need to change that shells rc file ~/.zshrc

@invalidusrname
Copy link
Author

Thanks @M-Dominguez, but I really don't want to have to enter my password every time I load up the shell. Installing pinentry seems to solve this for me (see solution.sh)

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