尝试使用Git提交时出现此错误。
gpg: skipped "name <name@mail.com>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
fatal: failed to write commit object
我已经生成了一个新密钥,但它仍然提供相同的错误
gpg --list-keys
~/.gnupg/pubring.gpg
--------------------------------
pub 2048R/35F5FFB2 2016-04-23
uid name (New key) <name@mail.com>
sub 2048R/112A8C2D 2016-04-23
密钥与上面的密钥相同
我找到了这个 Generating a GPG key for git tagging并按照步骤操作,但它仍然不起作用,任何想法?
答案 0 :(得分:57)
您需要在使用之前配置密钥。
git config user.signingkey 35F5FFB2
如果要为每个存储库使用相同的密钥,请将其全局声明。
git config --global user.signingkey 35F5FFB2
来源:https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work
答案 1 :(得分:45)
对我有用的是添加
where gpg2.exe
如果要查找gpg2.exe的完整路径:
cat <<EOF >file1
<h1 id="name">John Smith</h1>
<h2 id="customer-id">192238</h2>
<h3 id="current-date">Thu 13 Apr 2017</h3>
EOF
id="customer-id"
sed -r "/id=\"$id\"/ s/^<.[^>]*>/FOO/" file1
#Output
<h1 id="name">John Smith</h1>
FOO192238</h2>
<h3 id="current-date">Thu 13 Apr 2017</h3>
答案 2 :(得分:26)
这在Windows 10上对我有用
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
这是我在修复之前遇到的错误
gpg: skipped "3E81C*******": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
fatal: failed to write commit object
答案 3 :(得分:9)
我想完成所有这些答案,因为我遇到了很多问题。
这些示例使用--global
标志,但如果您想在本地使用这些内容,则可以将其删除。
git config --global user.signingkey 35F5FFB2
某些系统(例如Ubuntu)可以同时拥有gpg
和gpg2
。您需要指定您使用gpg2
git config --global gpg.program gpg2
如果您在ssh环境中使用这些命令,则可能会出现以下错误:Inappropriate ioctl for device
或gpg: échec de la signature : Ioctl() inapproprié pour un périphérique
。这可以通过以下方式解决:
export GPG_TTY=$(tty)
git config --global commit.gpgsign true
答案 4 :(得分:7)
在Windows 10计算机上,我遇到了同样的情况。
listen 4050;
命令listen 4050 ssl;
和$ git commit -m "Improve logging, imports and show time executed"
gpg: signing failed: Operation cancelled
gpg: signing failed: Operation cancelled
error: gpg failed to sign the data
fatal: failed to write commit object
给了我不同的结果!
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --list-secret-keys --keyid-format LONG
主要原因与先前的答案有关,但意义不同:
我希望这可以帮助那些偶然发现此消息并且以前的答案不能解决任何问题的人。
答案 5 :(得分:4)
您必须设置变量GNUPGHOME
。
没有它,GnuPG无法找到你的钥匙。
# On unix add it to your path
# On windows it will usually be under:
<drive>:\Users\<username>\AppData\Roaming\gnupg
在Unix上它只是将它添加到路径中 在Windows上,您必须打开控制面板并将其设置为
System Variable
Name: GNUPGHOME
Path: <drive>:\Users\<username>\AppData\Roaming\gnupg
答案 6 :(得分:2)
我最近发现了同样的 secret key not available
错误,并且发现了更多错误,例如未找到 GPG 代理。
就我而言,我希望提交签名并在 GitHub 上显示为已验证。
以下是使其在 Windows 10 x64 上运行的完整步骤:
我像这样安装了带有 winget
的 GPG 2.3.1:
C:\> winget install GnuPG.GnuPG
验证:
C:\> gpg --version
C:\> gpg --full-generate-key
添加您的真实姓名和电子邮件,与 GitHub 帐户中使用的相同。
密钥必须至少为 4096 位。
先列出key:
C:\> gpg --list-secret-keys --keyid-format=long
<块引用>
sec rsa4096/[short-key] 2021-06-14 [SC]
然后导出:
C:\> gpg --armor --export [short-key]
复制包含 BEGIN/END 文本的密钥。
-----BEGIN PGP PUBLIC KEY BLOCK-----
[huge-ascii-key]
-----END PGP PUBLIC KEY BLOCK-----
转到 Profile
> Settings
> SSH and GPG keys
> 新 GPG 密钥
或者请关注这些visual instructions。
C:\> git config --global user.signingkey [short-key]
C:\> git config --global commit.gpgsign true
C:\> git config --global gpg.program "C:/Program Files (x86)/gnupg/bin/gpg"
检查 GPG 代理:
gpg-agent --version
设置环境变量:
GNUPGHOME=%USERPROFILE%\AppData\Roaming\gnupg
生成的 .gitconfig
将具有如下所示的用户部分:
[user]
name = Your Name
email = your@email.com
signingkey = [short-key]
[commit]
gpgsign = true
[gpg]
program = C:/Program Files (x86)/gnupg/bin/gpg
答案 7 :(得分:0)
我有一个相同的问题,那就是.gitconfig 中存储的git 名称和电子邮件与提供的gpg密钥不同。我更改了它们以进行匹配,然后它开始起作用。
答案 8 :(得分:0)
使用"C:\Program Files\Git\usr\bin\gpg.exe"
是我的解决方案。
不得不卸载kleopatra。有了它,它就不起作用了。
所以,总结一下
不需要kleopatra,请改用GIT默认值。
git config --global user.signingkey Y0URK3Y
git config --global commit.gpgsign true
git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"
答案 9 :(得分:-3)
也许您需要克隆您拥有权限的自己的存储库。当我克隆另一个人的存储库时,我遇到了这个问题。