无法访问 gpg-agent

n1r*_*1r3 14 gnupg 16.04

在全新的 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 <nicolas@xxx.com>"
2048-bit RSA key, ID F5DECA47, created 2016-11-03

gpg: gpg-agent is not available in this session
Enter passphrase: 
Run Code Online (Sandbox Code Playgroud)

此外,似乎 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
Run Code Online (Sandbox Code Playgroud)

并且 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
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

n1r*_*1r3 15

回答我自己,以防其他人被困在这个问题上。

在 Ubuntu 16.04 上,默认版本是:

    # gpg --version
    gpg (GnuPG) 1.4.20
Run Code Online (Sandbox Code Playgroud)

    # gpg-agent --version
    gpg-agent (GnuPG) 2.1.11
Run Code Online (Sandbox Code Playgroud)

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

    # gpg2 --version
    gpg (GnuPG) 2.1.11
Run Code Online (Sandbox Code Playgroud)