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

本文讲述安装gpg后按官方文档配置时出现错误,经研究找到解决方案。还介绍了提交后点击比较与拉取请求链接会显示“已验证”标签,列出所有密钥ID信息,用GPG密钥提交,以及相关git操作信息和参考资料。

After install gpg, config step by step follow the offical doc, but when use

$ git commit -m "test gpg verfified"

It prompt error

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

after some research, when use

$ source ~/.bash_profile
nvm is not compatible with the npm config "prefix" option: currently set to "/Users/wangbingfeng/anaconda3"
Run `npm config delete prefix` or `nvm use --delete-prefix v6.10.0 --silent` to unset it.

The solution

npm config delete prefix

works for me.

After commited, click below Compare & pull request link

Compare & pull request

the "Verified tag" show.

list our all keyids info:

$ gpg --list-secret-keys --keyid-format LONG

 commit with gpg key:

$ git commit -S -m "add commit verified"
git config --global user.signingkey 3AA5C34371567BD2

3AA5C34371567BD2 is your GPG key ID (It is in the row behind sec rsa4096/). 

git operate info: https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches

references:

1. https://help.github.com/en/articles/managing-commit-signature-verification

2. https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work

3. https://seven.ooo/sign-git-commits-with-gpg-key/#%E6%AD%A5%E9%AA%A4

4. https://blog.iltc.io/en/how-to-sign-commits-and-tags-with-gpg.html

 

<think> 嗯...我需要帮用户解决GPG签名失败的问题。看到用户提供的信息:多个引用都提到gpg签名时出现"No secret key"的错误,涉及Git提交、Maven部署等场景。 这个问题很典型呢。用户遇到的错误信息明确显示系统找不到对应的私钥来签名。让我思考下背后的原因... 首先想到几个关键点: 1) GPG可能根本没安装或未配置正确路径——就像引用[5]提到的密钥导入问题 2) 密钥环里确实没有匹配的私钥,虽然用户以为有 3) 环境变量没设对,比如GPG_TTY或GPG_AGENT_INFO 4) 终端类型不支持,需要设置export GPG_TTY=$(tty) 用户具体报错里有邮箱bingxin.chen@qilu-pharma.com,说明很可能是密钥绑定问题。解决方法应该分步骤来: 第一步检查gpg --list-secret-keys看密钥是否存在。如果没有就要导入 第二步配置git config user.signingkey指向正确密钥ID 第三步确保终端能访问gpg-agent,可能需要killall gpg-agent重启 啊对了,引用[3]提到Kleopatra图形工具,其实命令行更直接。用户如果用的是Windows,可能需要额外设置gpg.exe路径 最后验证环节很重要:用echo "test" | gpg --clearsign测试签名能力,成功后再试git commit -S </think> 基于引用内容和GPG签名失败常见原因,以下是解决`gpg: signing failed: No secret key`错误的系统方法: ### 🔑 解决方法分步指南 1. **检查密钥是否存在** ```bash gpg --list-secret-keys --keyid-format LONG ``` - ✅ 确认输出中包含签名邮箱 `bingxin.chen@qilu-pharma.com` - ❌ 若未列出,说明私钥未导入或丢失(需执行[引用3]的导入操作) 2. **设置默认密钥(关键步骤)** ```bash # 获取密钥ID(例:9961AA14Bxxxxxxxx) gpg --list-secret-keys | grep sec -A 1 # 设为全局默认密钥 git config --global user.signingkey <your_key_id> # 替换为实际密钥ID ``` *这是[引用1][引用4]中报错的核心原因* 3. **配置GPG程序路径** ```bash # 适用于Windows/macOS/Linux通用方案 git config --global gpg.program $(which gpg) ``` *解决[引用2]中VS Code的路径识别问题* 4. **启动GPG代理(必要时)** ```bash gpgconf --launch gpg-agent export GPG_TTY=$(tty) # 必须设置TTY环境变量[^3] ``` 5. **测试签名功能** ```bash echo "test" | gpg --clearsign # 成功应输出PGP签名块 ``` ### ️ 特殊情况处理 - **密钥未导入**:按[引用5]方法导入 ```bash gpg --import your_private.key ``` - **Maven项目报错**:在`pom.xml`中显式指定密钥 ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <configuration> <keyname>你的密钥ID</keyname> <!-- 同步骤2的ID --> </configuration> </plugin> ``` *解决[引用3][引用4]的构建问题* - **Windows系统额外步骤**: 1. 安装[Gpg4win](https://www.gpg4win.org/) 2. 设置路径:`git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"` ### 📌 验证解决方案 ```bash # 测试Git提交签名 echo "test" > tmpfile git commit -S -m "GPG test" tmpfile # 成功后删除测试文件 ``` 成功标志:控制台显示`[master xxxxxxx] GPG test`并带Verified标签 > **重要提示**:若仍失败,检查密钥有效期:`gpg --list-keys`,过期密钥需用`gpg --edit-key <key_id>`然后输入`expire`更新[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值