Question: 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

Answer: 
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](https://unix.stackexchange.com/questions/647022/gpg-key-is-not-getting-generated-agent-genkey-in-gpg-is-looking-for-some-file/680853).]

In [this issue](https://github.com/MISP/MISP/issues/3702) 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](https://github.com/MISP/MISP/issues/2372#issuecomment-452786029) 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.