我刚开始使用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
当前回答
如果您使用智能卡/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
其他回答
检查你的钥匙是否过期。一旦你修复了过期日期(不需要创建一个新的密钥,除非你想),git将正常工作。
修复过期密钥的一种方法:
(注:$表示命令行提示符,在提示符后输入命令;每个命令后按Enter键)
$ gpg2—list-keys查找合适的密钥id (pub行\后的字符)
$ gpg2——edit-key <key id> -打开GPG shell,提示符更改为GPG >
Gpg > expire -按照指示设置主键的新过期日期
接下来,如果有子键过期(子键显示在行中),也重置它们的过期日期:
Gpg > key 1 -选择第一个子密钥 Gpg > expire -按照指示为子密钥设置新的过期日期
根据需要,对每个后续子键重复此操作。
这在ubuntu 18.04上对我有效
检查你的gpg密钥
gpg -K --keyid-format LONG
如果得到空白响应,则生成一个GPG密钥
gpg --generate-key
重新运行第一个命令,你应该得到一个输出:
sec rsa3072/95A854E0593B3214 2019-05-06 [SC] [expires: 2021-05-05]
AF2F7514568DC26B0EB97B9595A854E0593B74D8
uid [ultimate] yourname<your_email>
ssb rsa3072/EFD326E6C611117C 2019-05-06 [E] [expires: 2021-05-05]
设置git签名密钥
git config --global user.signingkey 95A854E0593B3214
然后你就可以开始了!(——global是可选的)
或者,如果您不介意用ssh密钥签名
git config commit.gpgsign false
请注意,由于这里和这里的问题存在安全问题,不建议这样做
我刚刚在VSCode更新时遇到了这个问题。我认为GPG代理挂起了,因为该命令在出错之前运行了几秒钟。运行gpgconf——kill gpg-agent重置并为我修复了它。
当GPG密钥过期时,也会发生此错误。生成一个新密钥并将其添加到Git中应该可以解决这个问题。
参考@sideshowbarker和@Xavier Ho解决方案,我通过以下步骤解决了我的问题。
假设gpg2通过brew安装,
git config --global gpg.program gpg2
brew install pinentry
gpgconf --kill gpg-agent
gpg2 -K --keyid-format SHORT
// no key found then generate new one
gpg2 --gen-key
gpg2 -K --keyid-format SHORT
... - dpg gnupg - pubring。
sec rsa2048/0A61C6FC 2017-06-29 [SC][有效期:2019-06-29]
git config --global user.signingkey 0A61C6FC
经同事提醒,需要追加
export GPG_TTY=$(tty)
~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile
For macOS,
gpg2在brew中与GPG结合,因此GPG命令指向gpg2
brew install gpg2
酿造信息GPG
Gnupg:稳定2.2.6(瓶装)
git config --global gpg.program gpg
gpg -K --keyid-format SHORT
还有pinentry-mac用于密码输入
brew install pinentry-mac
vim ~/.gnupg/gpg-agent.conf
添加一行
pinentry-program /usr/local/bin/pinentry-mac
经同事提醒,需要追加
export GPG_TTY=$(tty)
~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile