gpg 无法对数据进行致命签名:无法写入提交对象 [Git 2.10.0]

gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

我关注了 pretty attributes on Git 2.10 发行说明中的​​几篇文章。通过将 git 升级到 2.10.0 并对全局 .gitconfig 进行更改,结果如下 -

[filter "lfs"]
    clean = git-lfs clean %f
    smudge = git-lfs smudge %f
    required = true
[user]
    name = xyz
    email = abc.def@gmail.com
    signingkey = AAAAAAA
[core]
    excludesfile = /Users/xyz/.gitignore_global
    editor = 'subl' --wait
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
[color "diff"]
    old = red strike
    new = green italic

但现在我尝试使用

签署我的提交
git commit -a -S -m "message"

我看到以下错误 -

You need a passphrase to unlock the secret key for

user: "XYZ (Digitally Signed) "

2048-bit RSA key, ID AAAAAAAA, created 2016-07-01

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

注意 - 我仍然可以使用 git commit -a -m "message"

提交更改

有什么办法可以克服吗?或者 gpg 配置中需要的任何更改以适应 git?

的升级

更新 1

也在寻求进一步的有用性,关注 Is there a way to "autosign" commits in Git with a GPG key?。我已经使用

配置了密钥
git config --global user.signingkey ED5CDE14(with my key) 
git config --global commit.gpgsign true

很明显,无论如何都会遇到同样的错误。

2016 年 10 月更新:issue 871 确实提到了 "Signing stopped working in Git 2.9.3"

Git for Windows 2.10.1 两天前(2016 年 10 月 4 日)发布,修复了提交和标记的交互式 GPG 签名。

the recent gpg-sign change in git (which introduces no problem on Linux) exposes a problem in the way in which, on Windows, non-MSYS2-git interacts with MSYS2-gpg.


原回答:

正在读取“7.4 Git Tools - Signing Your Work", I assume you have your "”配置集。

围绕 gpg 的最后一次重大重构(在 Git 2.10 之前)是在 commit 2f47eae2a, here that error message was moved to gpg-interface.c

该文件的日志显示 commit af2b21e (Git 2.10)

最近的变化

gpg2 already uses the long format by default, but most distributions seem to still have "gpg" be the older 1.x version due to compatibility reasons. And older versions of gpg only show the 32-bit short ID, which is quite insecure.

This doesn't actually matter for the verification itself: if the verification passes, the pgp signature is good.
But if you don't actually have the key yet, and want to fetch it, or you want to check exactly which key was used for verification and want to check it, we should specify the key with more precision.

因此请检查您如何指定 user.signingkey 配置,以及您使用的 gpg 版本(gpg1 或 gpg2),看看这些是否对错误消息有任何影响。

还有commit 0581b54 which changes the condition for the gpg failed to sign the data error message (in complement to commit 0d2b664):

We don't read from stderr at all currently. However, we will want to in a future patch, so this also prepares us there (and in that case gpg does write before reading all of the input, though again, it is unlikely that a key uid will fill up a pipe buffer).

Commit 4322353 显示 gpg 现在使用临时文件,因此可能存在正确的问题。

Let's convert to using a tempfile object, which handles the hard cases for us, and add the missing cleanup call.

我运行陷入同样的​​问题。我很高兴地报告问题不在于 git 2.10.0 而在于 gnupg 1.4.21.

暂时将 gnupg 降级到 1.4.20 解决了我的问题。

如果您使用的是自制软件并且像我一样升级了您的软件包,您可能只需 运行 brew switch gnupg 1.4.20 即可还原。

我 运行 用 OSX 解决了这个问题。

原回答:

似乎(brew 的)gpg 更新更改为 gpggpg1 的位置,您可以更改 git 查找 gpg 的二进制文件:

git config --global gpg.program gpg1

如果你没有 gpg1: brew install gpg1.

更新的答案:

看起来 gpg1 已被弃用/"gently nudged out of usage",因此您可能实际上应该更新到 gpg2,不幸的是,这需要更多 steps/a 时间:

brew upgrade gnupg  # This has a make step which takes a while
brew link --overwrite gnupg
brew install pinentry-mac

旧自制软件:

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

在较新的系统上,如 M1 macs:

echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf 
killall gpg-agent

前半部分安装gpg2,后半部分是a hack required to use it. For troubleshooting, see (虽然是linux不是brew),建议好好测试一下:

echo "test" | gpg --clearsign  # on linux it's gpg2 but brew stays as gpg

如果此测试成功(没有 error/output 包含 PGP 签名),则您已成功更新到最新的 gpg 版本。

您现在应该可以再次使用 git 签名了!
值得注意的是,您需要:

git config --global gpg.program gpg  # perhaps you had this already? On linux maybe gpg2
git config --global commit.gpgsign true  # if you want to sign every commit

注意:在您 运行 签名提交后,您可以验证它是否已签名:

git log --show-signature -1

这将包括最后一次提交的 gpg 信息。

None 以上答案似乎符合我的问题。我的 gpg 二进制文件 (/usr/local/bin/gpg -> /usr/local/MacGPG2/bin/gpg2) 是作为 GPG Suite 的一部分安装的,而不是通过 brew 安装的。

尽管如此,我觉得建议归结为:"use whichever gpg binary is the latest available on brew"。所以我尝试了:

brew update
brew upgrade git
brew install gpg

# the following are suggestions from brew's Caveats, to make `/usr/local/bin/gpg`
# point to the brew binary:
rm '/usr/local/bin/gpg'
brew link --overwrite gnupg2

我确认我已正确更改 $PATH 上的 gpg 以指向来自 brew 的新可执行文件:

 which gpg
/usr/local/bin/gpg
 ls -l /usr/local/bin/gpg
lrwxr-xr-x  1 burger  admin  33 Feb 13 13:22 /usr/local/bin/gpg -> ../Cellar/gnupg2/2.0.30_3/bin/gpg

而且我还明确告诉 git 使用哪个 gpg 二进制文件:

git config --global gpg.program gpg

嗯,也许这并不完全无懈可击,因为它对路径很敏感。我实际上并没有毫无疑问地确认 git 已经切换到调用 brew gpg.

无论如何:none 这足以使 git commit 再次成功签署我的提交。


最终对我有用的是更新 GPG Suite。我是 运行 版本 2016.7,我发现更新到 2016.10 解决了我的问题。

我打开 GPG Keychain.app,然后点击 "Check for updates…"。使用新版本:签名提交再次正常工作。

如果使用gnupg2和gpg-agent2.x,一定要设置环境变量GPG_TTY.

export GPG_TTY=$(tty)

参见GPG’s documentation about common problems

确保您的电子邮件设置正确。

git config --global user.email "user@example.com"

我在最新的 Git 源代码 (2.12.2) 及其所有依赖项的最新源代码(Zlib、Bzip、cURL、PCRE、ReadLine、IDN2、iConv、Unistring)中遇到了类似的问题等)。

事实证明 libreadline 给 GnuPG 带来了问题:

$ gpg --version
gpg: symbol lookup error: /usr/local/lib/libreadline.so.7: undefined symbol: UP

当然,用 -vvv 试图从 Git 获取有用信息失败了,所以失败是个谜。

要解决由于 ReadLine 导致的 PGP 故障,请按照 Can't update or use package manager -- gpg error 中的说明进行操作:

In terminal:

ls /usr/local/lib

there was a bunch of readline libs in there (libreadline.so.BLAH-BLAH) so i:

su
mkdir temp
mv /usr/local/lib/libreadline* temp
ldconfig

如果这只是随机发生并且过去一直运行良好,就像我的情况一样,请尝试注销 (cmd+shift+q) 并重新登录。对我有用

可能有助于终止可能卡在旧数据中的进程 gpg-agent。所以新 gpg-agent 启动会要求输入密码。

如果与您的 GPG 密钥的 uid 关联的电子邮件与您在 git 中使用的电子邮件不同,您需要向您的密钥添加另一个用户 ID 或使用与电子邮件完全匹配的密钥。

您可以使用以下方式添加另一个 UID:

$ gpg --edit-key

见mo https://superuser.com/questions/293184/one-gnupg-pgp-key-pair-two-emails

我已经 完成了 通过这个 shorteasy 食谱:

macOS 上自动签署提交(全球和不同的 IDE):

this way 中获得你的 signingkey

brew install gnupg gnupg2 pinentry-mac
git config --global user.signingkey <YOUR_SIGNING_KEY>
git config --global commit.gpgsign true
git config --global gpg.program gpg

将以下内容放入 gpg.conf 文件(使用 nano ~/.gnupg/gpg.conf 命令编辑文件):

no-tty

将以下内容放入 gpg-agent.conf 文件(使用 nano ~/.gnupg/gpg-agent.conf 命令编辑文件):

pinentry-program /usr/local/bin/pinentry-mac

更新:

如评论中所建议,根据评论,您可能需要在编辑配置文件gpg.conf后执行killall gpg-agent命令。不用说这个命令会终止GPG(Gnu Privacy Guard)代理。

使用 cygwin,我最近切换到 gpg2。然后我在设置 git config gpg.program gpg2.

后用 git 签名时遇到了同样的问题

尝试 echo "test" | gpg2 --clearsign 查看 gpg2 是否正常工作。我发现设置 git config gpg.program gpg 是最简单的解决方案,因为它有效。但是你也会通过这种方式得到更好的错误 - 例如您需要安装 pinentry。

如果一切都失败了,请使用 GIT_TRACE=1 尝试查看 git 实际在做什么:

$ GIT_TRACE=1 git commit -m "Add page that always requires a logged-in user"
20:52:58.902766 git.c:328               trace: built-in: git 'commit' '-vvv' '-m' 'Add page that always requires a logged-in user'
20:52:58.918467 run-command.c:626       trace: run_command: 'gpg' '--status-fd=2' '-bsau' '23810377252EF4C2'
error: gpg failed to sign the data
fatal: failed to write commit object

现在 运行 手动失败的命令:

$ gpg -bsau 23810377252EF4C2
gpg: skipped "23810377252EF4C2": Unusable secret key
gpg: signing failed: Unusable secret key

事实证明,我的密钥已过期,git 不是罪魁祸首。

上面的答案很好,但对我不起作用。解决我的问题的是同时导出 publicsecret 密钥。

列出我们从

导出的 machine 的密钥
$ gpg --list-keys
/home/user/.gnupg/pubring.gpg
--------------------------------
pub 1024D/ABCDFE01 2008-04-13
uid firstname lastname (description) <email@example.com>
sub 2048g/DEFABC01 2008-04-13

导出密钥

$ gpg --output mygpgkey_pub.gpg --armor --export ABCDFE01
$ gpg --output mygpgkey_sec.gpg --armor --export-secret-key ABCDFE01

转到mac我们正在导入的文件并导入

$ gpg --import ~/mygpgkey_pub.gpg
$ gpg --allow-secret-key-import --import ~/mygpgkey_sec.gpg

宾果邦果,大功告成!

参考:https://www.debuntu.org/how-to-importexport-gpg-key-pair/

ps。我的钥匙最初是在训练营 windows 7 上制作的,我将它们导出到我的 mac 空气中(相同的物理 machine,虚拟不同)

通过以下方式轻松设置:

brew uninstall gpg 

brew install gpg2

使用以下命令检查是否启用了 gpg

git config -l | grep gpg

如果 returns 为真,运行 下面的命令将其禁用

git config --global --unset commit.gpgsign

成功 运行 执行上述命令后,您应该可以 运行 git 提交命令。

就我而言,其他答案中提到的 none 解决方案有效。我发现问题是特定于一个存储库的。再次删除并克隆回购协议解决了问题。

我的两分钱在这里:

当您创建密钥并将其添加到 gpg-agent 时,您定义了一个名为 passphrase 的东西。现在 passphrase 在某个时候过期了,gpg 需要您再次输入它来解锁您的密钥,以便您可以再次开始签名。

当您使用与 gpg 交互的任何其他程序时,gpg 提示您输入密码的提示 而不是 出现(基本上 gpg-agent 当守护进程无法显示 stdin) 中的输入对话框时。

其中一个解决方案是 gpg --sign a_file.txt 然后输入您在创建密钥时输入的密码,然后一切都应该没问题(gpg-agent 应该会自动签名)

请参阅 this answer 了解如何为您的密码设置更长的超时时间,这样您就不必一直这样做。

或者您可以使用 ssh-keygen -p

完全删除密码

编辑:man gpg-agent 阅读一些有关如何自动执行上述操作的内容,然后添加行:

GPG_TTY=$(tty)
export GPG_TTY

在你的 .bashrc 上,如果你使用 bash(这是正确的答案,但我也保持上面的思路) 然后获取您的 .bashrc 文件或重新登录。

非常像@birchlabs,经过大量 digging/searching 我发现它不是 GPG,而是 GPG Suite。我做了 cask reinstall gpg-suite,它帮我解决了。

git 痕迹非常揭示了我的情况...

   GIT_TRACE=1 git commit -m "a commit message"
   13:45:39.940081 git.c:344               trace: built-in: git commit -m 'a commit message'
   13:45:39.977999 run-command.c:640       trace: run_command: gpg --status-fd=2 -bsau 'full name <your-email@domain.com>'
   error: gpg failed to sign the data
   fatal: failed to write commit object

我需要根据 git 正在检查的格式生成一个初始密钥。最好将上面传递给 -bsau 的值原样复制到日志中并在下面使用。

所以就变成了,

   gpg --quick-generate-key "full name <your-email@domain.com>"

然后成功了。

我一定是不小心更新了 gpg,因为我在尝试测试 gpg 是否有效后得到了这个:

gpg: WARNING: server 'gpg-agent' is older than us (2.1.21 < 2.2.10)
gpg: Note: Outdated servers may lack important security fixes.
gpg: Note: Use the command "gpgconf --kill all" to restart them.

运行 gpgconf --kill all 帮我修好了。

可能是挂起的 gpg 代理。

尝试gpgconf --kill gpg-agentas discussed here

任何在 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> 并将此密钥添加到 GitHub 的 GPG 密钥:https://github.com/settings/keys(包括开始和结束行)

如果问题仍然存在:

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 文件 (请确保 Email 和 Name 与您在生成 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

按照以下 url 设置签名提交 https://help.github.com/en/articles/telling-git-about-your-signing-key

如果还在 gpg 无法对数据进行致命签名: 未能写入提交对象

这不是 git 的问题,这是 GPG 的问题 按照以下步骤

  1. gpg --version
  2. echo "test" | gpg --clearsign

如果显示:

gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device

  1. 然后使用export GPG_TTY=$(tty)

  2. 然后再试一次echo "test" | gpg --clearsign 其中获得了 PGP 签名。

  3. git config -l | grep gpg

gpg.program=gpg
commit.gpgsign=true
  1. 申请git commit -S -m "commitMsz"

我在 Ubuntu 18.04 遇到了同样的错误,也担心了好几个星期。 终于意识到 gpg2 没有指向任何东西。 所以简单 运行

git config --global gpg.program gpg

还有 tada,它很有魅力。

您的提交现在将带有经过验证的标签。

我偶然发现这个错误不是因为任何配置问题,而是因为我的密钥已过期。在 OSX 上延长其有效期的最简单方法是打开 GPG 钥匙串应用程序(如果您安装了它),它会自动提示您延长它。点击两下,大功告成。

我在 Ubuntu 18.04 上遇到这个错误,结果是我的 密钥已过期

为了看到这个,我 运行 确认我的密钥已过期:

gpg --list-keys

为了更正这个问题,我 运行(使用上一个命令中显示的 ID):

gpg --edit-key <ID>

从那里开始,我在 these instructions 之后延长了 key 0key 1 的到期时间,归结为输入 key 0 然后 expire 并按照提示进行操作.然后重复 key 1.

之后,为了测试这个,我 运行:

echo test | gpg --clearsign

在修复之前,它因错误而失败:

gpg: no default secret key: No secret key
gpg: [stdin]: clear-sign failed: No secret key

但是在修复之后,相同的命令成功地签署了消息,所以我知道事情又恢复了!

我见过类似的答案,但没有一个与对我有用的答案完全相同。在 Linux 上,我不得不终止并重新启动我的 gpg-agent

$ pkill gpg-agent
$ gpg-agent --daemon
$ git commit ...

这对我有用。看起来您确实需要将 user.signingkey 设置为您的私钥以及其他一些评论所说的内容。

$ git config --global user.signingkey [your_key_hash]

有点奇怪,但请确保您的终端足够大!您可以通过 运行 echo test | gpg --clearsign 判断它是否太小——它会给您一个非常明显的错误消息让您知道。如果它不够大,您的 GPG 代理将无法显示它的小 ncurses 框。

如果您使用 GUI 代理或不使用 ncurses 的东西,这将不适用。

这对我来说是在 Ubuntu 突然开始发生的,不确定最近的更新是否做到了,但是 none 的现有问题适用于我(我有 GPG_TTY 设置,尝试杀死代理等)。独立 gpg 命令失败并出现此错误:

$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

test
gpg: signing failed: Operation cancelled
gpg: [stdin]: clear-sign failed: Operation cancelled

我用 --debug-all 选项尝试了 运行 gpg 并注意到以下输出:

gpg: DBG: chan_3 <- INQUIRE PINENTRY_LAUNCHED 27472 gnome3 1.1.0 /dev/pts/6 screen-256color -
gpg: DBG: chan_3 -> END
gpg: DBG: chan_3 <- ERR 83886179 Operation cancelled <Pinentry>
gpg: signing failed: Operation cancelled

以上表明 pinentry 程序存在一些问题。 Gpg 通常为我运行 pinentry-curses,所以我将其更改为 pinentry-tty(我必须先 aptitude install)并且错误消失了(尽管我不再获得全屏密码输入,但是反正我不喜欢那样)。要进行此更改,我必须将行 pinentry-program /usr/bin/pinentry-tty 添加到 ~/.gnupg/gpg-agent.conf 并使用 gpgconf --kill gpg-agent 终止代理(下次重新启动)。

在 OS X 上,通过 brew 使用 gnupg2 我只需要 杀死 gpg 代理 ,有时会发生:

pkill -9 gpg-agent

并根据需要设置 env 变量:

export GPG_TTY=$(tty)

参见 Common GPG problems also and

对我来说,brew 已经更新了 gnupggpg 所以我要做的就是解决这个问题。

brew link --overwrite gnupg

gpg 链接到正确的位置,我可以通过 which gpg 确认,之后一切正常。

运行 在 prezto 另一个 zsh 变体中。问题是我的 git 存储库是新的,没有将 node_modules 添加到 .gitignore。我将 node_modules 添加到 .gitignore 后,问题就不再存在了。所以我的假设是 git-info 由于这些大 node_modules.

需要时间

如果你不想处理 brew 来安装 gpg,这似乎 运行 有时会出现问题,只需从 GPG Tools 下载 gpg 工具。

在执行向导时,单击自定义安装并取消选择邮件插件(除非您想使用它)。这些工具似乎没有 运行 任何问题,而且它会在您第一次签名后记住您的密码。不需要额外的配置,除了告诉 git about which key 使用。

至少这是我的经验。

在我的例子中,none 的解决方案是有效的,因为我没有手动进入我的 ~/.gitconfig 并删除以下内容,因为我创建了一个不再是我的旧 X 的新密钥。 509 密钥所以我删除了以下内容然后我的新密钥开始工作。

[gpg]
    program = gpg
    format = x509
[gpg "x509"]
    program = smimesign

None 以上对我有用,我通常使用我的 IDE 终端。

我时常遇到这个错误,在大多数情况下它工作得很好。 我在 运行

之后发现了问题
 echo "test" | gpg --clearsign

gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small

解决方案:增加终端 window 大小。

如果您在没有 Rosetta 的 M1 芯片上使用 homebrew,您需要指定 pinentry-program 二进制文件的不同位置,因为它安装在不同的位置。

Andy Hayden 的更新答案应修改如下:

brew upgrade gnupg  # This has a make step which takes a while
arch -arm64 brew link --overwrite gnupg
arch -arm64 brew install pinentry-mac
echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

如果您像我一样使用 WSL 和 IDE,您可能遇到过这个问题,因为在使用 IDE的提交界面(WSL还不支持GUI应用)

修复方法是简单地使用命令行 git,因为它有自己的 cli window 供您输入密码。您还需要确保终端 'big' 足以弹出(我知道这令人惊讶)

我每次在我的 macOS 上注销然后再次登录时都会收到该错误。解决方案只是一个简单的命令:

killall gpg-agent

我认为这只是 gpg 代理的一个错误,将其杀死然后重新运行。

如果您的问题是 Visual Studio 代码 不允许提交,但您已经设置了 GPG 签名 bash 的一行答案是:

git config --global gpg.program `which gpg2`

如果 PATH 中有 gpggpg2 中没有,则只需使用它即可。

除了没有正确设置 git 的 gpg 密钥外,另一个可能的问题是: 尝试从带有 X 转发的 ssh 会话内部提交。 在这种情况下,它可能会尝试调用一个 GUI,如果未设置环境变量 DISPLAY,该 GUI 将失败。

您可以通过编辑 ~/.gnupg/gpg-agent.conf:

强制 gpg-agent 使用仅 tty 工具
pinentry-program /usr/bin/pinentry-tty

然后重新加载配置文件:

gpg-connect-agent reloadagent /bye

(当然要先安装pinentry-tty)

在我的例子中,问题出在 ~/.gitconfiggpg 的相对名称。我把它改成这个,问题就消失了(Monterey,Macbook M1):

[gpg]
    program = /opt/homebrew/bin/gpg

解释很简单:当 git 尝试 运行 gpg 时,它在新的 shell 中执行,没有 运行ning ~/.profile 我为自制程序配置 PATH 的地方。所以,它根本找不到gpg

经过大量搜索,我发现 gpg 密钥是我的问题所在。

要检查 gpg 密钥是否对您有问题,请首先检查以下输出:

GIT_TRACE=1 git commit -m 'message'

如果出现问题,您将看到如下内容:

10:37:22.346480 run-command.c:637       trace: run_command: gpg --status-fd=2 -bsau <your GPG key>

这里显示的是我的 GPG 密钥中的姓名和电子邮件,但这应该有密钥。你可以试试 运行 gpg --status-fd=2 -bsau <your GPG key>

要更新正确的密钥,请执行以下操作: 检查密钥使用: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

我正在使用 M1 Mac,我尝试了上面最常见的解决方案但没有用,我的问题是这里缺少 GPG 二进制文件 = > usr/local/bin

最初,我通过 brew 安装了 GPG,我尝试了 re-installing 但找不到它存储的二进制文件,后来我从这里安装了 GPG Suite GUI => GPG Suite Tools 成功了。

最后,我可以 sign-in 在 Github 上提交并获得验证徽章。