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

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

What am I missing ?

  • Start the agent with --log-file [myfile] and see if it gives you any errors in the log. – Raniz Dec 19 '16 at 12:50
  • The right error message I have is gpg: gpg-agent is not available in this session. If I had a log how you suggest, all I have get is : 2016-12-19 13:39:39 gpg-agent[10957] gpg-agent (GnuPG) 2.1.11 started – n1r3 Dec 19 '16 at 13:43
  • I tried to manually set GPG_AGENT_INFO, but I don't know how to know what to set ... that's when I got a gpg: problem with the agent - disabling agent use. – n1r3 Dec 19 '16 at 13:45
  • As root, setting export GPG_AGENT_INFO=/var/lib/postgresql/.gnupg/S.gpg-agent:0:1 works, but not as a user. Also, it seems that I would have to do that manually, no? – n1r3 Dec 19 '16 at 13:45
  • Did you add this GPG_TTY=$(tty) export GPG_TTY to your .bashrc file as stated in the _man gpg-agent page ? – George Udosen Dec 20 '16 at 17:36

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


    # 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

The solution is to install gpgv2 :

sudo apt install gpgv2

This is because gpg-agent that comes with Ubuntu is version 2 and it tries to connect to gpg with version 2. But Ubuntu has gpg version 1 installed.

  • 3
    probably you meant gnupg2 – Dmitriusan Feb 23 '18 at 12:30
  • No, it only worked after installing gpgv2. I tried with gnupg2 but it didn't work. – phoxd Mar 2 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.