gpg配置踩坑

最近配置gpg时遇到了一些问题,在这里记录一下。

在导入gpg key时提示gpg: error receiving key from agent: No such file or directory

解决方案:

gpg --gen-key --homedir /home/NEWUSER/.gnupg --passphrase "PASSWORD" --pinentry-mode loopback

其中关键在于使用--pinentry-mode loopback参数。关于这个参数,文档是这样解释的:

loopback
Use a loopback pinentry. This fakes a pinentry by using inquiries back to the caller to ask for a passphrase. This option may only be set if the agent has been configured for that. To disable this feature use option --no-allow-loopback-pinentry.

从文档来看,使用这个参数会让gpg从—-passphrase参数中读取密码,而不是弹出密码输入框。

不过,完全不加参数也可以导入,这时gpg会弹出CLI形式的密码输入框。

在macOS中配置vscode gpg密码输入

解决方案:

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

原理非常清晰明了,就是在gpg-agent.conf中指定pinentry-program。在wsl中配置gpg-agent的方法类似。


参考链接:

  1. https://unix.stackexchange.com/questions/571597/gpg-key-gen-fails-no-such-file-or-directory
  2. https://github.com/microsoft/vscode/issues/43809

本文链接:

https://www.direcore.xyz/archives/27/
1 + 3 =
快来做第一个评论的人吧~