gpg: problem with the agent: Permission denied

13,500

Try using the PIN entry mode of loopback:

gpg --decrypt --pinentry-mode=loopback <file>

I can replicate your issue on my Linux system when I try GPG with a terminal su:

$ gpg --decrypt example.gpg
gpg: AES256 encrypted data
gpg: problem with the agent: Permission denied
gpg: encrypted with 1 passphrase
gpg: decryption failed: No secret key

The solution that works for me:

$ gpg --decrypt --pinentry-mode=loopback example.gpg
hello world

You may also want to verify that your GPG is up to date:

$ gpg --version
gpg (GnuPG) 2.2.4
libgcrypt 1.8.1
...
Share:
13,500

Related videos on Youtube

sashoalm
Author by

sashoalm

174zen6JGRNCbNFUoGJeNvrPX1oQ4cAbkZ

Updated on September 18, 2022

Comments

  • sashoalm
    sashoalm almost 2 years

    GPG fails with gpg: problem with the agent: Permission denied when I invoke it after switching my user with su:

    su - user2
    gpg --symmetric --passphrase=foo foo.txt
    

    If I invoke the command from my own user, it doesn't fail. Is there a workaround?

    I found a thread a thread in their mailing list about it but it's unanswered. It speculates that the error is because:

    the tty is owned by the original user I logged into via SSH, not the user I switched to via su

    • Amith KK
      Amith KK over 5 years
      Did you try script -c "gpg --symmetric --passphrase foo foo.txt" /dev/null/
    • jueti
      jueti about 4 years
      I fix it by logging in user2 directly instead su from other users.
  • Deathgrip
    Deathgrip almost 3 years
    Can also add pinentry-mode loopback to your ~/.gnupg/gpg.conf file.
  • carlin.scott
    carlin.scott over 2 years
    @Deathgrip your comment was more helpful to me than the answer. Every single command requires the --pinetry-mode option, so saving it to the config is a lifesaver.
  • Deathgrip
    Deathgrip over 2 years
    Glad I can help