Today I faced two errors:

  • gpgkeys: key ... not found on keyserver
  • no writable keyring found: eof

while trying to add new key for Python by:

gpg --recv-key AA65421D

Two errors were raised:

gpg: no keyserver known (use option --keyserver)
gpg: keyserver receive failed: bad URI

and

    gpg: failed to create temporary file `/home/user/.gnupg/.#lk0x959f251.user-MS-8A74.29456': Permission denied
gpg: keyblock resource `/home/user/.gnupg/secring.gpg': general error
gpg: failed to create temporary file `/home/user/.gnupg/.#lk0x959f751.user-MS-8A74.29456': Permission denied
gpg: keyblock resource `/home/user/.gnupg/pubring.gpg': general error

Adding server and change folder ownership

Note - Later I found that due to lack of permission the server was not found so you can go the recommended settings below.

First I tried to follow suggestions and add server to the command by:

gpg --keyserver hkp://keyserver.ubuntu.com --recv-key AA65421D

Then I faced error:

gpg: requesting key AA65421D from hkp server keyserver.ubuntu.com
gpg: no writable keyring found: eof

The problem was related to rights for folder .gnupg. You can check permissions by:

sudo ls -al .gnupg

If the root is the owner of the folder you need to assigned it to you by:

sudo chown user /home/user/.gnupg/pubring.gpg

General recommendations for .gnupg

The recommended settings for this folder .gnupg are:

  • The folder should belong to your user:
chown -R $(whoami) ~/.gnupg/
  • Access rights:
chmod 600 ~/.gnupg/*
chmod 700 ~/.gnupg