我正在设置新的机器(macOS塞拉利昂)的网页开发,我已经做了brew install gpg,其中安装了gpg2和gpg-agent。我在我的旧mac上复制了~.gnupg的钥匙。我并没有安装我在旧机器上安装的mac接口GPG套件,因为我真的更喜欢使用命令行。
我已经用适当的设置设置了我的git全局。
git config --global user.name "Christopher Allen"
git config --global user.email "ChristopherA@LifeWithAlacrity.com"
git config --global user.mail "ChristopherA@LifeWithAlacrity.com"
git config --global user.signingKey F8D36C91357405ED当我尝试将更改提交到git存储库(需要git config commit.gpgsign=true )时,在我的旧git上,我会看到一个弹出窗口,它在窗口中询问我的密码。但是,只使用GPG,它可以正确地找到我的公钥,但它不会提示我要签名的密码。
$ git commit -S -m "changed code"
You need a passphrase to unlock the secret key for
user: "Christopher Allen <ChristopherA@LifeWithAlacrity.com>"
4096-bit RSA key, ID 357405ED, created 2015-04-16
error: gpg failed to sign the data
fatal: failed to write commit object
$ 在这里研究时,我看到的唯一提到的是" to ask for my GPG password“,它表明问题在于gpg-agent的环境变量(没有建议的解决方案),或者使用gpg-预设的-密码函数(我不喜欢这样)。
进一步检查,gpg-agent似乎没有运行:
$ gpg-agent
gpg-agent: no gpg-agent running in this session我发现这个页面https://blog.chendry.org/2015/03/13/starting-gpg-agent-in-osx.html建议将这个脚本添加到.bash_profile中:
[ -f ~/.gpg-agent-info ] && source ~/.gpg-agent-info
if [ -S "${GPG_AGENT_INFO%%:*}" ]; then
export GPG_AGENT_INFO
else
eval $( gpg-agent --daemon --write-env-file ~/.gpg-agent-info )
fi 在找到这个脚本之后,gpg-agent说:
$ gpg-agent
gpg-agent: gpg-agent running and available不过,我仍然有同样的问题。
有什么办法解决这个问题吗?我不喜欢使用旧的GPG套件,恢复到GPG 1.0,或者使用gpg-预设-密码。
谢谢!
-克里斯托弗·艾伦
发布于 2017-02-26 20:33:41
我实际上为解决这个问题所做的是:
安装插孔
brew install pinentry
如果这样做不起作用,那么:
告诉GPG当它询问密码时使用哪个tty
export GPG_TTY=$(tty)
这个真的帮我修好了。
您还可以将此导出添加到您的~/.bashrc中,以便它将自动导出--不要忘记重新加载文件或启动新会话。
一种简单的方法:echo "export GPG_TTY=$(tty)" >> ~/.bashrc
如果您得到这个错误:
gpg-agent: no gpg-agent running in this session
将问题中提到的脚本添加到~/.bashrc文件中。
[ -f ~/.gpg-agent-info ] && source ~/.gpg-agent-info
if [ -S "${GPG_AGENT_INFO%%:*}" ]; then
export GPG_AGENT_INFO
else
eval $( gpg-agent --daemon --write-env-file ~/.gpg-agent-info )
fi 测试gpg是否有效
echo "Hello" | gpg -s
随机的,它仍然不要求密码
当git不要求我提供密码时,有时我会使用上面的test命令来提示它,这将被缓存,然后,我尝试提交我的更改。
增加密码缓存时间
如果要缓存更长时间的密码,可以在配置文件中添加以下行:~/.gnupg/gpg-agent.conf
default-cache-ttl 86400发布于 2016-09-24 00:02:48
问题是,我从~.gnupg复制了所有文件,后者覆盖了brew install gpg创建的文件(可能是.conf文件之一)。
我卸载了gpg和所有相关的子包(其中有很多),首先将pubring.gpg、secring.gpg和trustdb.gpg复制到~.gnupg中,然后再复制brew install gpg。创建了新的gpg.conf和gpg-agent.conf。
-克里斯托弗·艾伦
发布于 2021-05-11 17:53:56
所有的答案对我都没有用。
我不得不杀了那个代理,然后叫提交-S
gpgconf --kill gpg-agent
git commit -S -am "some message"
https://stackoverflow.com/questions/39669830
复制相似问题