无法连接 gpg-agent

无法连接 gpg-agent

在全新安装的 Ubuntu 16.04 上,我想使用 gpg 来加密我的数据库备份,但无法正常工作gpg-agent

postgres@db:~$ gpg -s test.txt

You need a passphrase to unlock the secret key for
user: "Nicolas Remond <[email protected]>"
2048-bit RSA key, ID F5DECA47, created 2016-11-03

gpg: gpg-agent is not available in this session
Enter passphrase: 

另外,似乎 gpg-agent 正在运行,因为我之前做过以下事情:

postgres@db:~$ gpg-agent
gpg-agent[1715]: no gpg-agent running in this session
postgres@db:~$ gpg-connect-agent /bye
gpg-connect-agent: no running gpg-agent - starting '/usr/bin/gpg-agent'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: connection to agent established
postgres@db:~$ pidof gpg-agent
1762

gpg 配置有以下use-agent设置:

postgres@dbmaster0:~$ cat ~/.gnupg/gpg.conf | grep use-agent
# For Ubuntu we now use-agent by default to support more automatic
use-agent

我错过了什么?

答案1

我回答我自己,以防其他人也遇到这个问题。

在 Ubuntu 16.04 上,默认版本是:

    # gpg --version
    gpg (GnuPG) 1.4.20

    # gpg-agent --version
    gpg-agent (GnuPG) 2.1.11

它们不兼容。必须使用 GPG2:

    # gpg2 --version
    gpg (GnuPG) 2.1.11

答案2

解决方案是安装gpgv2

sudo apt install gpgv2

这是因为 Ubuntu 自带的 gpg-agent 是版本 2,它尝试连接到版本 2 的 gpg。但 Ubuntu 安装的是 gpg 版本 1。

相关内容