Unable to generate a key with GnuPG (agent_genkey failed: No such file or directory)

When running gpg --gen-key, I get:

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

I tried killall gpg-agent and gpgconf --kill gpg-agent. My private-keys-v1.d is created, within ~/.gnupg.

I am also not able to delete secret keys:

gpg: deleting secret key failed: No such file or directory
gpg: deleting secret subkey failed: No such file or directory

EDIT:

I tried removing .gnupg and reinstalling gpg, still having the issue.


Solution 1:

The directory ~/.gnupg/private-keys-v1.d may under some circumstances not be created or perhaps created with the wrong permissions.

Try this:

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

Look also for any strange files in the .gnupg directory that may need to be deleted.