gpg --gen-key fails with `gpg: agent_genkey failed: Permission denied`
Issue
When generating keys as an unprivileged user, gpg --gen-key fails to access the tty to prompt for a password.
RHEL 8,9
[user@r9 ~]$ gpg --gen-key
gpg (GnuPG) 2.3.3; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory '/home/user/.gnupg' created
gpg: keybox '/home/user/.gnupg/pubring.kbx' created
Note: Use "gpg --full-generate-key" for a full featured key generation dialog.
GnuPG needs to construct a user ID to identify your key.
Real name: TheUser
Email address: TheUser@redhat.com
You selected this USER-ID:
"TheUser <TheUser@redhat.com>"
Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: agent_genkey failed: No pinentry
Key generation failed: No pinentry
RHEL 7
[user@r7 ~]$ gpg --gen-key
GnuPG needs to construct a user ID to identify your key.
Real name: TheUser
Email address: TheUser@redhat.com
Comment:
You selected this USER-ID:
"TheUser <TheUser@redhat.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
gpg: cancelled by user
gpg: Key generation canceled.
Environment
Red Hat Enterprise Linux 7
Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 9
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.