36

I'm trying to generate a gpg key

$ gpg --full-gen-key

but eventurally I get an error

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

I'm on Arch Linux.

$ gpg --version
gpg (GnuPG) 2.1.15
libgcrypt 1.7.3
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/me123/.gnupg
.............

The directory /home/me123/.gnupg exists

Meji
  • 471
  • 1
  • 4
  • 5
  • 3
    Run `strace -o /tmp/foo gpg --full-gen-key` and then review the output. Should then be clear what file or directory it's not finding. – steve Oct 23 '16 at 20:04
  • 1
    If that doesn't solve it, you could also start `gpg-agent` with `strace`, just in case the error comes from there: `pkill gpg-agent; strace -o /tmp/gpg-agent.trace gpg-agent --daemon`. – Matei David Oct 24 '16 at 14:47

4 Answers4

56

Did you delete the /home/me123/.gnupg directory and then it was recreated by gpg? If so, that's likely what is confusing the agent.

Either restart the agent (gpgconf --kill gpg-agent) or, more drastically, reboot your machine and try again.

BenR
  • 103
  • 3
tupiniquim
  • 661
  • 4
  • 4
19

It would appear that the directory ~/.gnupg/private-keys-v1.d (under some circumstances) is not being created or, is created with the wrong permissions.

# mkdir -p ~/.gnupg/private-keys-v1.d
# chmod 700 ~/.gnupg/private-keys-v1.d

Fixed it for me.

Alien Life Form
  • 621
  • 5
  • 12
3

Just want to add to this old thread, in case someone comes here looking for answers, that I had a similar issue on macOS (Big Sur 11.2). After deleting the .gnupg directory I had the same error as OP. The ~/.gnupg/private-keys-v1.d directory was recreated by GnuPG and had the correct permissions. Also, killing gpg-agent was not enough.

I noticed a strange file in the .gnupg directory named something like .#k0x0000000130605a20.MBP-van-##REDACTED##.52431. After I deleted that file, GnuPG worked like a charm again!

justClouds
  • 51
  • 5
0

[Crossposting from a related question.]

In this issue this was called expected behaviour with the reason being a lack of ownership of the terminal-related device file. This can happen when e.g. starting the terminal as regular user, but running the gpg command as root via su or sudo.

Instead of doing wild stunts with chmod in the /dev tree, this comment demonstrates a quick fix using tmux. Basically just run the same gpg command within a tmux session, as tmux will take care of proper device file ownership.