I'm facing issue to generate gpg key on my mac(10.15.7 Catalina). It is showing some error that the agent_genkey is looking for some file which is not available. Below is the debug information from that :

% gpg --gen-key -vvvvv   
gpg (GnuPG) 2.3.1; 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: using character set 'utf-8'
gpg: Note: RFC4880bis features are enabled.
gpg: directory '/Users/test/.gnupg' created
gpg: keybox '/Users/test/.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: test name
Email address: [email protected]
You selected this USER-ID:
    "test name <[email protected]>"

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: no running gpg-agent - starting '/usr/local/Cellar/gnupg/2.3.1/bin/gpg-agent'
gpg: waiting for the agent to come up ... (5s)
gpg: connection to the agent established
gpg: pinentry launched (12023 curses 1.1.1 /dev/ttys002 xterm-256color - ? 502/20 0)
gpg: agent_genkey failed: No such file or directory
Key generation failed: No such file or directory

gpg version is 2.3.1 and git version is 2.30.0.

% gpg --version
gpg (GnuPG) 2.3.1
libgcrypt 1.9.3

I have tried suggestions given in various post : like deleting the home directory (~/.gnupg), stopping the gpg-agent, reinstalling the gpg package (using brew).

It had worked around 1 month back. There was some issue with the previous keys . So, I had to delete those all and generate fresh and that is where the problem started. Before reinstalling it, it was timing out in generation of gpg key . I had ran dd commands to help generate randomness. But that did not work either.


1 Answer 1


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.

  • I can verify that the TMUX trick in the comment works. Thanks! (although I still have no idea what the underlying issue is... )
    – tdensmore
    Commented May 7, 2023 at 22:50

You must log in to answer this question.

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