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

时间:2017-01-06 09:00:45

标签: git macos gnupg

我从brew安装了GPG。

brew install gpg

是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

我使用了命令:

gpg --list-secret-keys | grep ^sec

它让我回来了:

sec   2048R/1111AAAA 2017-01-05

然后我使用了这个命令:

git config --global user.signingkey 1111AAAA

commit会给我回复相同的错误消息。

我该如何解决这个问题?

8 个答案:

答案 0 :(得分:20)

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

brew install pinentry-mac

因此安装并再次尝试可能让事情正常进行。但如果没有,另一件事就是确保git使用/找到合适的GPG程序。这些天你真的应该使用gpg2,所以如果你还没有安装,请执行:

brew install gnupg2

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

git config --global gpg.program gpg2

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

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

echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf

...然后再试一次。

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

答案 1 :(得分:2)

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

  1. brew uninstall gpg
  2. brew install gpg2
  3. brew install pinentry-mac(如果需要)
  4. gpg --full-generate-key通过使用算法创建密钥。
  5. 通过执行以下命令获取生成的密钥:gpg --list-keys
  6. 在这里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. 如果要将密钥导出到GitHub,请:gpg --armor --export <key> 并将此密钥通过GPG密钥添加到GitHub:https://github.com/settings/keys(包括START和END行)

如果问题仍然存在:

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

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

如果问题仍然存在:

安装https://gpgtools.org并通过从菜单栏中按 Sign 对您使用的密钥进行签名: Key -> Sign

如果问题仍然存在:

转到:您的全局.gitconfig文件,以我为例:⁨/Users/gent/.gitconfig 并修改 .gitconfig 文件(请确保“电子邮件”和“名称”与您在生成密钥时创建的名称相同)

[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

p.s 我从以前的答案中得到了这个答案: gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

答案 2 :(得分:1)

您的问题假设您实际上是签名。如果不这样做,则修复非常简单-关闭提交签名:

git config --global commit.gpgsign false

就我而言,我继承了一些默认的git config设置,其中包括提交签名。

答案 3 :(得分:0)

我有同样的错误消息,并发现我的密钥已过期。 因此,最好使用以下方法检查密钥的过期时间:

<set-query-parameter name="ExternalCustomerId" exists-action="append"> <value>@(context.Request.Url.Query.GetValueOrDefault("CustomerId"))</value> </set-query-parameter>

如果您的密钥也已过期,则可以使用以下方法调整过期日期:

gpg --list-keys

然后:

gpg --edit-key <YOUR_KEY>

答案 4 :(得分:0)

改为安装GPGSuite,它具有用于生成密钥的GUI。

您可以查看更多详细信息here

答案 5 :(得分:0)

如果您仍然在macOS中遇到问题, 打开~/.gitconfig 并将[gpg]以下的任何内容更改为 program = /usr/local/bin/gpg

答案 6 :(得分:0)

在我的情况下, user.signingkey 设置错误....复制正确的signingkey解决了问题

enter image description here

答案 7 :(得分:0)

我在 macOS 上运行 brew upgrade 并且它破坏了我的 gpg 登录 git,大概是在它更新 gpg 包时。我认为有一种更简单的方法可以强制 gpg 服务正确重启(我假设升级包时正在运行的某些东西坏了),但我对此的修复非常简单:只需重新启动计算机。