Chr*_*len 7 git macos github gnupg pgp
我正在为web开发设置新机器(macOS Sierra),我已经完成brew install gpg了已安装gpg2和gpg-agent.我从~.gnupg旧Mac上复制了我的钥匙.我没有安装我在旧机器上的mac接口GPG Suite,因为我真的更喜欢使用命令行.
我已经使用适当的设置设置了我的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
Run Code Online (Sandbox Code Playgroud)
当我尝试将更改提交到需要的git存储库git config commit.gpgsign=true时,在我的旧GPG Suite上,我会弹出一个窗口,询问我的密码.但是,仅使用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
$
Run Code Online (Sandbox Code Playgroud)
在这里研究,我唯一提到的是" 我不能得到`git tag -s`来询问我的GPG密码 ",它表明问题在于环境变量gpg-agent(没有建议的解决方案),或者使用gpg-preset-passphrase函数(我不想这样做).
进一步检查,似乎gpg-agent没有运行:
$ gpg-agent
gpg-agent: no gpg-agent running in this session
Run Code Online (Sandbox Code Playgroud)
我发现此页面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
Run Code Online (Sandbox Code Playgroud)
在采购此脚本后,gpg-agent说:
$ gpg-agent
gpg-agent: gpg-agent running and available
Run Code Online (Sandbox Code Playgroud)
但是,我仍然有同样的问题.
有想法该怎么解决这个吗?我不想使用旧的GPG套件,还原为GPG 1.0,或使用gpg-preset-passphrase.
谢谢!
- 克里斯托弗艾伦
小智 5
我实际上为解决这个问题所做的是:
brew install pinentry
如果这不起作用,那么:
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
Run Code Online (Sandbox Code Playgroud)
echo "Hello" | gpg -s
当 git 不会要求我输入密码时,有时我会使用上面的测试命令来获得提示,这将被缓存,然后我尝试提交我的更改。
如果您想将密码缓存更长的时间,您可以将以下行添加到配置文件中: ~/.gnupg/gpg-agent.conf
default-cache-ttl 86400
Run Code Online (Sandbox Code Playgroud)
事实证明,问题是我复制了来自 的所有文件,这覆盖了由(可能是其中一个文件)~.gnupg创建的文件。brew install gpg.conf
我卸载了 gpg 和所有相关的子包(有很多),仅复制pubring.gpg,secring.gpg并trustdb.gpg放入~.gnupg FIRST,然后执行brew install gpg。新的gpg.conf和gpg-agent.conf被创造的。
——克里斯托弗·艾伦
| 归档时间: |
|
| 查看次数: |
1536 次 |
| 最近记录: |