gpg-agent can't be reached

10,366

Solution 1

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

Solution 2

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.

Share:
10,366

Related videos on Youtube

n1r3
Author by

n1r3

Updated on September 18, 2022

Comments

  • n1r3
    n1r3 over 1 year

    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 <[email protected]>"
    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 ?

    • Raniz
      Raniz over 7 years
      Start the agent with --log-file [myfile] and see if it gives you any errors in the log.
    • n1r3
      n1r3 over 7 years
      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
      n1r3 over 7 years
      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
      n1r3 over 7 years
      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?
    • George Udosen
      George Udosen over 7 years
      Did you add this GPG_TTY=$(tty) export GPG_TTY to your .bashrc file as stated in the _man gpg-agent page ?
    • David Foerster
      David Foerster over 7 years
      Could you please check if you have an agent running for your user already with pgrep -xu "$USER" gpg-agent? What's the value of the GPG_AGENT_INFO environment variable (check with echo "$GPG_AGENT_INFO")? Depending on the outcome I'll ask further questions.
    • n1r3
      n1r3 over 7 years
      @George: Indeed, I did had it already
    • n1r3
      n1r3 over 7 years
      @DavidFoerster: pgrep -xu "$USER" gpg-agent gives me 8572 and the GPG_AGENT_INFO is empty, which I don't understand why?
    • David Foerster
      David Foerster over 7 years
      Ok, that's a good start for an investigation. Let's make sure that gpg-agent can work at all. Please terminate the existing agent (pkill -xu "$USER" gpg-agent), start a new one and have your shell “source” its output: eval $(gpg-agent --daemon). Then try to use the agent, e. g. with gpg -s some-file.
    • Elder Geek
      Elder Geek over 7 years
  • Dmitriusan
    Dmitriusan about 6 years
    probably you meant gnupg2
  • phoxd
    phoxd about 3 years
    No, it only worked after installing gpgv2. I tried with gnupg2 but it didn't work.