Ubuntu – gpg-agent can’t be reached

16.04gnupg

On a fresh Ubuntu 16.04 install, I would like to use gpg to cypher my database backups, but I can't have the gpg-agent working.

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: 

Also, it seems that a gpg-agent is running as I did the following before:

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

And the gpg config has the use-agent setting:

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

What am I missing ?

Best Answer

Answering myself in case someone else is stuck on this.

On Ubuntu 16.04, the default versions are:

    # gpg --version
    gpg (GnuPG) 1.4.20

and

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

They are not compatible. It is mandatory to use GPG2:

    # gpg2 --version
    gpg (GnuPG) 2.1.11