git - mac osx 上的 gpg:错误:gpg 未能对数据进行签名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41502146/
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 - gpg onto mac osx: error: gpg failed to sign the data
提问by Mondy
I installed GPG from brew.
我从 brew 安装了 GPG。
brew install gpg
It is gnupg2-2.0.30_2.
它是 gnupg2-2.0.30_2。
When I commit, I do get a error message:
当我提交时,我确实收到一条错误消息:
You need a passphrase to unlock the secret key for
user: "Max Mustermann (mycomment) <[email protected]>"
2048-bit RSA key, ID 1111AAAA, created 2017-01-05
error: gpg failed to sign the data
fatal: failed to write commit object
I used the command:
我使用了命令:
gpg --list-secret-keys | grep ^sec
and it gives me back:
它让我回来:
sec 2048R/1111AAAA 2017-01-05
Then I used this command:
然后我使用了这个命令:
git config --global user.signingkey 1111AAAA
commit gives me back the same error message.
提交给了我同样的错误信息。
How can I solve this problem?
我怎么解决这个问题?
回答by sideshowbarker
If you're not getting prompted at all for a passphrase (you don't mention whether you are or not…), the solution may just be to also install a program to facilitate that. The most common is pinentry.
如果根本没有提示您输入密码(您没有提到您是否...),解决方案可能只是安装一个程序来促进这一点。最常见的是松香。
brew install pinentry-mac
So installing that and trying again mayget things working. But if not, another thing to do is make sure git
it using/finding the right GPG program. These days you really should be using gpg2
, so if you don't already have that installed, do:
因此,安装并重试可能会使事情正常进行。但如果没有,另一件事是确保git
它使用/找到正确的 GPG 程序。这些天你真的应该使用gpg2
,所以如果你还没有安装它,请执行以下操作:
brew install gnupg2
And then, to tell git
that's the GPG program want to you, this:
然后,为了告诉git
您 GPG 计划想要您,这个:
git config --global gpg.program gpg2
At that point, try your commit again and things may just work.
那时,再次尝试您的提交,事情可能会奏效。
But if not, then try this:
但如果没有,那么试试这个:
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
…and then try again.
……然后再试一次。
Note:Per some comments below, in order for this change to take effect, you apparently might need to reboot after making the change.
注意:根据下面的一些评论,为了使此更改生效,您显然可能需要在更改后重新启动。
回答by Gent Berani
To anybody who is facing this issue on MacOSmachines, try this:
对于在MacOS机器上遇到此问题的任何人,请尝试以下操作:
brew uninstall gpg
brew install gpg2
brew install pinentry-mac
(if needed)gpg --full-generate-key
Create a key by using an algorithm.- Get generated key by executing:
gpg --list-keys
- Set the key here
git config --global user.signingkey <Key from your list>
git config --global gpg.program /usr/local/bin/gpg
git config --global commit.gpgsign true
- If you want to export your Key to GitHub then:
gpg --armor --export <key>
and add this key to GitHub at GPG keys: https://github.com/settings/keys(with START and END line included)
brew uninstall gpg
brew install gpg2
brew install pinentry-mac
(如果需要的话)gpg --full-generate-key
使用算法创建密钥。- 通过执行获取生成的密钥:
gpg --list-keys
- 在这里设置密钥
git config --global user.signingkey <Key from your list>
git config --global gpg.program /usr/local/bin/gpg
git config --global commit.gpgsign true
- 如果您想将您的密钥导出到 GitHub,则:
gpg --armor --export <key>
并将此密钥添加到 GitHub 的 GPG 密钥:https: //github.com/settings/keys(包括 START 和 END 行)
If the issue still exists:
如果问题仍然存在:
test -r ~/.bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile
test -r ~/.bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile
echo 'export GPG_TTY=$(tty)' >> ~/.profile
echo 'export GPG_TTY=$(tty)' >> ~/.profile
If the issue still exists:
如果问题仍然存在:
Install https://gpgtools.organd sign the key that you used by pressing Signfrom the menu bar: Key->Sign
安装https://gpgtools.org并通过按菜单栏中的Sign对您使用的密钥进行签名:Key-> Sign
If the issue still exists:
如果问题仍然存在:
Go to: ??your global .gitconfig
file which in my case is at: ??/Users/gent/.gitconfig
And modify the .gitconfigfile (please make sure Email and Name are the same with the one that you have created while generating the Key):
转到:??您的全局.gitconfig
文件,在我的情况下位于:?? /Users/gent/.gitconfig
并修改.gitconfig文件(请确保 Email 和 Name 与您在生成 Key 时创建的相同):
[user]
email = [email protected]
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
p.sI took this answer from my previous answer here: gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]
ps我从我之前的答案中得到了这个答案: gpg 未能签署数据致命:无法写入提交对象 [Git 2.10.0]
回答by A5308Y
I had the same error message and found that my key was expired. So it might be a good idea to check your key expiration with:
我有同样的错误信息,发现我的密钥已过期。因此,通过以下方式检查您的密钥过期可能是个好主意:
gpg --list-keys
gpg --list-keys
If your key is expired as well you can adjust the expiration date with:
如果您的密钥也已过期,您可以通过以下方式调整过期日期:
gpg --edit-key <YOUR_KEY>
gpg --edit-key <YOUR_KEY>
and then:
进而:
gpg> expire
...enter the new expiration date...
gpg> save
回答by donturner
Your question assumes that you actually wantto sign your commits. If you don't, the fix is very simple - switch off commit signing:
您的问题假设您确实想要签署您的提交。如果你不这样做,修复很简单 - 关闭提交签名:
git config --global commit.gpgsign false
In my case I had inherited some default git config settings which included commit signing.
就我而言,我继承了一些默认的 git 配置设置,其中包括提交签名。