8

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

2
  • Did you try script -c "gpg --symmetric --passphrase foo foo.txt" /dev/null/
    – Amith KK
    Oct 2, 2018 at 7:21
  • I fix it by logging in user2 directly instead su from other users.
    – jueti
    Jun 14, 2020 at 8:27

1 Answer 1

17
+50

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
...
3
  • 2
    Can also add pinentry-mode loopback to your ~/.gnupg/gpg.conf file.
    – Deathgrip
    Jul 23, 2021 at 21:50
  • @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. Feb 9 at 20:05
  • Glad I can help
    – Deathgrip
    Feb 10 at 21:06

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.