git - gpg到mac osx:错误:gpg无法签署数据

Mon*_*ndy 20 git macos gnupg

我从brew安装了GPG.

brew install gpg
Run Code Online (Sandbox Code Playgroud)

这是gnupg2-2.0.30_2.

当我提交时,我收到一条错误消息:

You need a passphrase to unlock the secret key for
user: "Max Mustermann (mycomment) <mm@test.de>"
2048-bit RSA key, ID 1111AAAA, created 2017-01-05 

error: gpg failed to sign the data
fatal: failed to write commit object
Run Code Online (Sandbox Code Playgroud)

我使用了命令:

gpg --list-secret-keys | grep ^sec
Run Code Online (Sandbox Code Playgroud)

它让我回来:

sec   2048R/1111AAAA 2017-01-05
Run Code Online (Sandbox Code Playgroud)

然后我用这个命令:

git config --global user.signingkey 1111AAAA
Run Code Online (Sandbox Code Playgroud)

commit给了我相同的错误消息.

我怎么解决这个问题?

sid*_*ker 30

如果你没有得到密码提示(你没有提到你是否......),解决方案可能只是安装一个程序来促进这一点.最常见的是松树.

brew install pinentry-mac
Run Code Online (Sandbox Code Playgroud)

所以安装并重新尝试可能会让事情变得有效.但如果没有,另一件事就是确保git它使用/找到合适的GPG程序.这些天你真的应该使用gpg2,所以如果你还没有安装,请执行:

brew install gnupg2
Run Code Online (Sandbox Code Playgroud)

然后,告诉git那是GPG计划想要你,这个:

git config --global gpg.program gpg2
Run Code Online (Sandbox Code Playgroud)

此时,再次尝试提交,事情可能会奏效.

但如果没有,那试试这个:

echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
Run Code Online (Sandbox Code Playgroud)

......然后再试一次.

注意:根据下面的一些注释,为了使此更改生效,您显然可能需要在进行更改后重新启动.

  • 对我来说,重新启动gpg-agent是可行的,所以我不需要重新启动:`gpgconf --kill gpg-agent` (7认同)
  • 我按照上面的步骤,但需要重新启动才能使用 (4认同)
  • 我必须杀死`gpg-agent`并使用`gpg-agent --daemon`重新启动 (4认同)
  • 安装`pinentry-mac` 解决了我的问题。谢谢! (3认同)

Gen*_*ani 7

对于在MacOS计算机上面临此问题的任何人,请尝试以下操作:

  1. brew uninstall gpg
  2. brew install gpg2
  3. brew install pinentry-mac (如果需要的话)
  4. gpg --full-generate-key 通过使用算法创建密钥。
  5. 通过执行以下命令获取生成的密钥: gpg --list-keys
  6. Set the key here git config --global user.signingkey <Key from your list>
  7. git config --global gpg.program /usr/local/bin/gpg
  8. git config --global commit.gpgsign true
  9. If you want to export your Key to GitHub then: gpg --armor --export <key> and add this key to GitHub at GPG keys: https://github.com/settings/keys (with START and END line included)

If the issue still exists:

test -r ~/.bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile

echo 'export GPG_TTY=$(tty)' >> ~/.profile

If the issue still exists:

Install https://gpgtools.org and sign the key that you used by pressing Sign from the menu bar: Key->Sign

If the issue still exists:

Go to: ??your global .gitconfig file which in my case is at: ??/Users/gent/.gitconfig And modify the .gitconfig file (please make sure Email and Name are the same with the one that you have created while generating the Key):

[user]
	email = gent@youremail.com
	name = Gent
	signingkey = <YOURKEY>
[gpg]
	program = /usr/local/bin/gpg
[commit]
	gpsign = true
	gpgsign = true
[filter "lfs"]
	process = git-lfs filter-process
	required = true
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
[credential]
	helper = osxkeychain
Run Code Online (Sandbox Code Playgroud)

p.s I took this answer from my previous answer here: gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

  • GPGTools 就是为我做的,似乎提示输入密码,然后将其添加到钥匙串中:) (4认同)

A53*_*08Y 5

我有同样的错误信息,发现我的密钥已过期。因此,通过以下方式检查您的密钥过期可能是个好主意:

gpg --list-keys

如果您的密钥也已过期,您可以通过以下方式调整过期日期:

gpg --edit-key <YOUR_KEY>

进而:

gpg> expire
...enter the new expiration date...
gpg> save
Run Code Online (Sandbox Code Playgroud)