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, 2016 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. Oct 24, 2016 at 14:47

5 Answers 5


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!


[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.

  • What if I don't have tmux because my pacman is broken
    – Fifnmar
    Jul 8, 2023 at 13:09

Adding this line to my .zshrc worked for me:

export GPG_TTY=$(tty)
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 18, 2023 at 14:47
  • 1
    I have spent days trying everything I could think of, looking through forums, internet search results, etc., and this is the first thing that worked for me. Mar 4 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .