I believe I've read and tried all the suggestions, starting with this post about the exact same issue.

I'm trying to generate a new key with:

gpg --full-generate-key

and it keeps ending with:

gpg: agent_genkey failed: No such file or directory
Key generation failed: No such file or directory

Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64), headless

gpg --version

gpg (GnuPG) 2.2.4
libgcrypt 1.8.1
Home: /home/mark/.gnupg
Supported algorithms:
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

I've killed gpg-agent and restarted the server multiple times.

gpgconf --kill gpg-agent

ps aux | grep gpg-agent

mark      1637  0.0  0.0  14428  1052 pts/0    S+   13:55   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn gpg-agent

The .gnupg directory permissions:

drwx------ 3 mark mark 4.0K Mar 6 14:01 .gnupg

I've deleted ~/.gnupg multiple times, rebooting each time for good measure:

ls -la ~/.gnupg

total 12K
drwx------  3 mark mark 4.0K Mar  6 14:00 .
drwxr-xr-x 17 mark mark 4.0K Mar  6 14:01 ..
drwx------  2 mark mark 4.0K Mar  6 14:00 private-keys-v1.d

I've repeated the following several times with the same result:

Trying to generate gpg key

ls -la ~/.gnupg

total 16K
drwx------  3 mark mark 4.0K Mar  6 14:01 .
drwxr-xr-x 17 mark mark 4.0K Mar  6 14:04 ..
drwx------  2 mark mark 4.0K Mar  6 14:00 private-keys-v1.d
-rw-------  1 mark mark   32 Mar  6 14:01 pubring.kbx

I changed pubring.kbx to 700 and ran again, same result (grasping at straws)

ps aux | grep gpg-agent

 mark      1751  0.0  0.0  93316  3348 ?        SLs  14:02   0:00 /usr/bin/gpg-agent --supervised
 mark      1758  0.0  0.0  14428  1084 pts/0    S+   14:06   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn gpg-agent

I also ran with strace but not sure how to decipher that output. Last line is +++ exited with 2 +++

strace -o /tmp/foo gpg --full-generate-key

I'm at a loss here.

  • Thanks for the link but it's the same one I linked to in the first line of this post. That looked promising but my issue persists. You can see above the screenshot, that directory exists with permissions 700 as described in that answer. – Mark Mar 6 '20 at 23:43
  • Mark sorry I totally missed that. Is SELinux maybe causing the issue? – Valentin Bajrami Mar 7 '20 at 8:22
  • @ValentinBajrami no, SELinux is not enabled - this is a box in a closet used for testing/learning. I try to avoid any extra security measures to keep things simple and avoid possible confusion, like you mentioned. – Mark Mar 7 '20 at 18:07
  • Mark did you try it with another user? – Valentin Bajrami Mar 8 '20 at 8:39
  • @ValentinBajrami - I did not but after reading your question I did and it worked, with two different users. So I tried it again using my account and it worked this time. The only difference I can think of is that the machine had been powered down completely instead of just being rebooted. Thanks for the suggestion. – Mark Mar 10 '20 at 2:25
gpg --gen-key --homedir /home/NEWUSER/.gnupg --passphrase "PASSWORD" --pinentry-mode loopback

I ran into something that looked a lot like this...

In my case it was because I had gpg-agent running and had deleted the files it was referring to in order to "start again". By killing the old gpg-agent I resolved the issue.

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.