Git 错误 - gpg 未能签署数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41052538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git error - gpg failed to sign data
提问by Entitize
I just started using git and I install git and gpg via homebrew.
For some reason, I get this error when i do git commit
I looked at so many other stackoverflow questions regarding this topic and none of them worked for me.
How can I fix this error so that I can upload successfully.
我刚开始使用 git,我通过自制软件安装了 git 和 gpg。出于某种原因,当git commit
我查看有关此主题的许多其他 stackoverflow 问题时,我收到此错误,但没有一个对我有用。如何修复此错误以便我可以成功上传。
error: gpg failed to sign the data
fatal: failed to write commit object
回答by sideshowbarker
For troubleshooting, two things to first try:
对于故障排除,首先要尝试两件事:
- run
git config --global gpg.program gpg2
, to make sure git usesgpg2
and notgpg
- run
echo "test" | gpg2 --clearsign
, to make suregpg2
itself is working
- 运行
git config --global gpg.program gpg2
,以确保 git 使用gpg2
而不是gpg
- 运行
echo "test" | gpg2 --clearsign
,以确保gpg2
它自己正在工作
If that all looks all right, one next thing to try:
如果一切正常,接下来要尝试的一件事:
- run
brew install pinentry
to ensure you have a good tool installed for passphrase entry
- 运行
brew install pinentry
以确保您安装了用于密码输入的好工具
If after that install and you re-try git commit
and still get the "failed to sign the data
" error:
如果在安装之后您重新尝试git commit
并仍然收到“ failed to sign the data
”错误:
- run
gpgconf --kill gpg-agent
to kill any running agent that might be hung
- 运行
gpgconf --kill gpg-agent
以杀死任何可能挂起的正在运行的代理
If that says gpgconf
isn't installed or doesn't have a --kill
option, you mighttry this:
如果说gpgconf
没有安装或没有--kill
选项,你可以试试这个:
cp ~/.gnupg ~/.gnupg-GOOD
to save a copy of your~/.gnupg
to revert to later if neededbrew install gnupg21
to install GnuPG 2.1
cp ~/.gnupg ~/.gnupg-GOOD
保存您的副本以在~/.gnupg
需要时恢复brew install gnupg21
安装 GnuPG 2.1
The reason for saving a copy of your ~/.gnupg
dir is that GnuPG 2.1 potentially creates/changes some key data in way that isn't backward-compatible with GnuPG 2.0 and earlier, so ifyou want to go back later, you can do mv ~/.gnupg ~/.gnupg21 && mv ~/.gnupg-GOOD ~/.gnupg
.
保存~/.gnupg
目录副本的原因是 GnuPG 2.1 可能会以与 GnuPG 2.0 及更早版本不向后兼容的方式创建/更改一些关键数据,因此如果您想稍后返回,您可以执行mv ~/.gnupg ~/.gnupg21 && mv ~/.gnupg-GOOD ~/.gnupg
.
Otherwise there are some basic steps to run to check you've got a working GnuPG environment:
否则,需要运行一些基本步骤来检查您是否有一个可用的 GnuPG 环境:
- run
gpg2 -K --keyid-format SHORT
, to check that you have at least one key pair
- 运行
gpg2 -K --keyid-format SHORT
,检查您是否至少有一对密钥
If the output of that shows you have no secret key for GnuPG to use, then you need to create one:
如果输出显示您没有 GnuPG 可以使用的密钥,那么您需要创建一个:
- run
gpg2 --gen-key
, to have GnuPG walk you through the steps for creating a key pair
- 运行
gpg2 --gen-key
,让 GnuPG 引导您完成创建密钥对的步骤
If you get an error message saying “Inappropriate ioctl for device”, do this:
如果您收到一条错误消息,指出“设备的 ioctl 不合适”,请执行以下操作:
- run
export GPG_TTY=$(tty)
and/or add that to your~/.bashrc
or?/.bash_profile
- 运行
export GPG_TTY=$(tty)
和/或将其添加到您的~/.bashrc
或?/.bash_profile
回答by Xavier Ho
Git needs to know which key it is signing with.
Git 需要知道它正在使用哪个密钥进行签名。
After you have setup GPG, gpg-agent, and your gpg.conf files (see this guide), you need to run
设置好 GPG、gpg-agent 和 gpg.conf 文件后(请参阅本指南),您需要运行
git config --global user.signingkey EB11C755
Obviously, replace the public key at the end with your own. If you want every commit to be signed by default, use
显然,将最后的公钥替换为您自己的公钥。如果您希望默认情况下对每个提交进行签名,请使用
git config --global commit.gpgsign true
回答by Jason Thrasher
Somehow your git is configured to GPG sign every commit. Signing with GPG isn't required to commit or push using git. It's likely giving the error because your gpg signing mechanism isn't configured yet.
不知何故,你的 git 被配置为 GPG 签署每个提交。使用 git 提交或推送不需要使用 GPG 签名。可能会出现错误,因为您的 gpg 签名机制尚未配置。
If you're new to git, try to get it working first without GPG signing at first, then add signing in later if you really need it.
如果您是 git 新手,请先尝试让它在没有 GPG 签名的情况下运行,然后在您确实需要时添加登录。
You can verify how your git is configured with regards to gpg by doing:
您可以通过执行以下操作来验证您的 git 是如何针对 gpg 配置的:
git config -l | grep gpg
Which may produce zero or more lines, including:
这可能会产生零个或多个行,包括:
commit.gpgsign=true
If "commit.gpgsign" is true, then you have gpg signing enabled. Disable it with:
如果“commit.gpgsign”为真,则您启用了 gpg 签名。禁用它:
git config --global --unset commit.gpgsign
Then try to run your commit again. It should now run without gpg signing. After you get the basic git working, then you should try adding gpg signing back to the mix.
然后尝试再次运行您的提交。它现在应该在没有 gpg 签名的情况下运行。在您获得基本的 git 工作之后,您应该尝试将 gpg 签名重新添加到组合中。
回答by V-SHY
Refer to @sideshowbarker, and @Xavier Ho solution, I solved my problem via following steps.
参考@sideshowbarker 和@Xavier Ho 解决方案,我通过以下步骤解决了我的问题。
Assume gpg2 installed by brew,
假设 brew 安装了 gpg2,
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
.../.gnupg/pubring.gpg
sec rsa2048/0A61C6FC2017-06-29 [SC] [expires: 2019-06-29]
.../.gnupg/pubring.gpg
秒 rsa2048/ 0A61C6FC2017-06-29 [SC] [过期:2019-06-29]
git config --global user.signingkey 0A61C6FC
Reminded by my colleague, need to append
同事提醒,需要追加
export GPG_TTY=$(tty)
to ~/.zshrc if using zsh, else append to ~/.bash_profile
如果使用 zsh,则添加到 ~/.zshrc,否则附加到 ~/.bash_profile
For macOS,
对于 macOS,
the gpg2 is combined with gpg in brew and hence the gpg command is pointed to gpg2
gpg2 在 brew 中与 gpg 结合,因此 gpg 命令指向 gpg2
brew install gpg2
brew info gpg
gnupg: stable 2.2.6 (bottled)
酿造信息gpg
gnupg:稳定 2.2.6(瓶装)
git config --global gpg.program gpg
gpg -K --keyid-format SHORT
and there has pinentry-mac for passphrase entry
并且有用于密码输入的 pinentry-mac
brew install pinentry-mac
vim ~/.gnupg/gpg-agent.conf
Add line
添加行
pinentry-program /usr/local/bin/pinentry-mac
pinentry-program /usr/local/bin/pinentry-mac
回答by Jamal Kaksouri
I am using it. It has support for zsha and works on Windows Subsystem for Linux:
我正在使用它。它支持 zsha 并适用于 Linux 的 Windows 子系统:
export GPG_TTY=$(tty)
回答by leanne
Check for your key to be expired. Once you fix the expiration date (no need to create a new key unless you want to), git
will work as normal.
检查您的密钥是否已过期。一旦您修复了到期日期(除非您愿意,否则无需创建新密钥),git
将正常工作。
One way to fix the expired key:
修复过期密钥的一种方法:
(Note: $
represents command line prompt, type the commands after the prompt; press Enter after each command)
(注:$
代表命令行提示符,在提示符后输入命令;每条命令后按回车)
$ gpg2 --list-keys
to find the appropriate key id (characters after \
on pub
line)
$ gpg2 --list-keys
找到相应的密钥ID(后面的字符\
上pub
线)
$ gpg2 --edit-key <key id>
- this opens the gpg shell, with prompt changed to gpg>
$ gpg2 --edit-key <key id>
- 这将打开 gpg shell,提示更改为 gpg>
gpg> expire
- follow instructions to set new expiration date for primary key
gpg> expire
- 按照说明为主键设置新的到期日期
Next, if there are subkeys that are expired (sub
shows on the line), reset their expiration dates, too:
接下来,如果有过期的子键(sub
显示在行上),也重置它们的过期日期:
gpg> key 1
- selects first subkey
gpg> expire
- follow instructions to set new expiration date for subkey
gpg> key 1
- 选择第一个子项
gpg> expire
- 按照说明为子项设置新的到期日期
Repeat for each subsequent subkey, as needed.
根据需要对每个后续子项重复此操作。
回答by poon gilbert
This worked for me on ubuntu 18.04
这在 ubuntu 18.04 上对我有用
Check your gpg key
检查您的 gpg 密钥
gpg -K --keyid-format LONG
if you get a blank response ,generate a GPG key
如果你得到一个空白的响应,生成一个 GPG 密钥
gpg --generate-key
rerun the first command, you should get an output as:
重新运行第一个命令,你应该得到如下输出:
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]
set git singing key
设置git唱歌键
git config --global user.singingkey 95A854E0593B3214
then you are good to go! (--global is optional)
那你就可以走了!(--global 是可选的)
Alternatively if you dont mind signing with your ssh key
或者,如果您不介意使用 ssh 密钥进行签名
git config commit.gpgsign false
note that this is not recommended due to a security issue according to this question hereand here
回答by fty4
I had to fix the gpg.program to the absolute path to gpg:
我必须将 gpg.program 修复为 gpg 的绝对路径:
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
I am using Windows with cygwin.
我正在使用带有 cygwin 的 Windows。
回答by carp
I experienced this problem after upgrading to gnupg 2.x. It would seen that gpg2 is referencing keys differently: I still had signingkey = ABC98F11
(gpg v1 setting) in my ~/.gitconfig
. The key identifiers for gpg2 are longer. Look them up with gpg --list-secret-keys
升级到 gnupg 2.x 后,我遇到了这个问题。会看到 gpg2 以不同的方式引用键:signingkey = ABC98F11
我的~/.gitconfig
. gpg2 的密钥标识符更长。看看他们gpg --list-secret-keys
回答by osowskit
This error can also occur when your GPG key has expired. Generating a new key and adding it to Git should resolve this.
当您的 GPG 密钥过期时,也会发生此错误。生成一个新密钥并将其添加到 Git 应该可以解决这个问题。