37

When I do git commit -a -S -m "Commit Message", I get this error:

You need a passphrase to unlock the secret key for
user: "Username (Gpg Key) <email-id>"
2048-bit RSA key, ID 2487BE7C, created 2016-10-03

error: gpg failed to sign the data
fatal: failed to write commit object

But, it doesn't even ask/prompts for my passphrase when I commit. So, how and where do I enter my passphrase while using gpg's -S flag?

2
  • 1
    Are you sure gpg can read input? If stdin is closed, you would see the above error message. If the git command is not run in an interactive shell, then you might need to have gpg-agent running in order to handle the passphrase input.
    – G. Sliepen
    Commented Oct 3, 2016 at 10:47
  • @G.Sliepen Possible to tell how to start it please?
    – Dawny33
    Commented Oct 3, 2016 at 10:58

3 Answers 3

44

I had the similar thing. I had the gpg and gpg2 binaries, both pointing to GPG version 2.0.30. I wasn't being prompted for my passphrase.

In your bash profile (I did it in my .zshrc file) add the following line:

export GPG_TTY=$(tty)
2
  • Thanks a lot, this works for me in my bash on macOS.
    – gpanda
    Commented Jun 28, 2017 at 16:40
  • Forgot all about .zshrc I've been trying this from other posts but in my .bashrc whoops! This worked, thanks!
    – CTS_AE
    Commented Aug 28, 2020 at 9:34
13

It stopped prompting me, so I had to kill the daemon

ps aux | grep gpg
mark              3129   0.0  0.0  4397952    820   ??  Ss    8Mar19   0:28.84 gpg-agent --homedir /Users/Mark/.gnupg --use-standard-socket --daemon
mark             18137   0.0  0.0  4286492    848 s000  R+    3:43pm   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn gpg

then

sudo kill -9 3129

Then it worked. It may be a slightly different issue.

1
  • 4
    This solved the issue for me. Seems like I exited the previous prompt in a bad way which confused the daemon. Commented Jun 24, 2019 at 9:24
1

If you are using OSX. It seems like a gpg update (of brew) changed to location of gpg to gpg1, you can change the binary where git looks up the gpg:

git config --global gpg.program gpg1

See this medium blog post.

1
  • For me it's still gpg but it won't ask for password and fail. Any other recommendation? Commented Nov 4, 2016 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.