GnuPG (gpg --verify, git verify-commit / verify-tag / log --show-signature)Git
错误信息
gpg: Can't check signature: No public key
也可能输出为
- gpg: Can't check signature: no public key
GnuPG 2.4 输出的是“No public key”;本地化翻译和较旧的构建版本在大小写上可能有所不同。Git 的验证命令会以非零状态退出,并原样转发 gpg 的输出。
含义
对象是签过名的,gpg 也找到了签名,但密钥环中没有与颁发者指纹匹配的公钥,因此无法判断签名是好是坏。前面几行(“Signature made …”、“using … key <fingerprint>”)告诉你需要哪个密钥。这不是签名验证失败,而是缺少密钥。
原因
从未导入签名者的密钥
常见新机器、CI 运行器、单独的 `GNUPGHOME`,或者某位你从未收到其密钥的团队成员。
没有自动获取密钥
偶见除非配置了 `auto-key-retrieve` 和密钥服务器,否则 GnuPG 不会自动获取密钥;许多密钥服务器不再提供未经验证的用户 ID。
签名子密钥比你本地的公钥副本新
偶见如果签名者添加了新的签名子密钥,你手上旧的公钥副本中就没有它。从密钥的来源处刷新该密钥。
修复方法
- 1.
从可信来源导入密钥
从项目网站、版本说明或密钥服务器导入,并在信任签名之前通过另一条渠道核对指纹。
bash # Import the signer's key from a trusted source, then compare the fingerprint out of band curl -sSL https://example.com/release-signing-key.asc | gpg --import gpg --fingerprint release@example.com git verify-commit HEAD - 2.
使用平台公开的密钥
GitHub 在 `https://github.com/<user>.gpg` 提供每个用户已添加的 GPG 密钥。
bash # Keys a GitHub user registered for signing (verify the fingerprint before trusting it) curl -sSL https://github.com/<user>.gpg | gpg --import
相关错误
gpg: BAD signature from "Release Bot <release@example.com>" [ultimate]GnuPG (gpg --verify, git verify-commit / verify-tag)error: gpg failed to sign the dataGit (commit -S, tag -s, commit.gpgsign) with GnuPGerror: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh sign…Git (verify-commit, log --show-signature, merge --verify-signatures) with gpg.format=ssh