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

  • 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

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.


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.


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!

New contributor
justClouds is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.