我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
当前回答
解决方案:
Issue: Disabled loopback pinentry mode
要解决这个问题,你需要在~/.gnupg/gpg.conf中启用环回pinentry模式:
cat <<'EOF' >> ~/.gnupg/gpg.conf
use-agent
pinentry-mode loopback
EOF
还有~/.gnupg/gpg-agent.conf(如果文件不存在就创建文件):
cat <<'EOF' >> ~/.gnupg/gpg-agent.conf
allow-loopback-pinentry
EOF
然后使用echo RELOADAGENT | gpg-connect-agent重新启动代理,您应该可以运行了!
源
其他回答
经过大量搜索,我发现gpg密钥是我的情况下的问题。
如果您的gpg密钥正确,您可以尝试运行gpg——status-fd=2 -bsau <您的gpg密钥>。
要更新正确的密钥,请执行以下操作: 检查密钥使用:GPG——list-secret-keys——keyid-format=long
它应该有以下输出:
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid Hubot
ssb 4096R/42B317FD4BA89E7A 2016-03-10
然后更新密钥使用:
git config --global user.signingkey 3AA5C34371567BD2
现在再次检查提交,如果关键字是问题,它应该成功。您需要设置密码短语来更新密钥,您可以使用GitHub文档进行更新。
更多详情见:https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374
在我的例子中,当在一个小的tmux窗口上运行git提交时,这个错误发生了,这个窗口不能适合密码短语提示。
$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
test
gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small
如果您使用智能卡/yubikey存储您的GPG密钥,并且您通过存储在卡中的密钥设置了git配置的signkey(并且上面所有的答案似乎都不能解决您的问题),您的卡的PIN被阻塞可能是这个问题的根本原因。
检查被阻止的PIN码:
gpg --card-status
如果计数器类似于
Reader ...........: Yubico YubiKey
PIN retry counter : 3 0 3
然后你的PIN被阻止(3次不成功尝试后)。
解锁密码:
gpg --card-edit
gpg/card> admin
Admin commands are allowed
gpg/card> passwd
gpg: OpenPGP card no. … detected
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? 2
PIN unblocked and new PIN set.
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? q
我必须修好gpg。编程到gpg的绝对路径:
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
我正在使用Windows cygwin。
我刚刚在VSCode更新时遇到了这个问题。我认为GPG代理挂起了,因为该命令在出错之前运行了几秒钟。运行gpgconf——kill gpg-agent重置并为我修复了它。