Apt key issues in Debian and Ubuntu Linux

Especially after adding new sources to your /etc/apt/sources.list you might get an error like the following after sudo apt-get update:

W: GPG error: http://www.any.url lsb3.2 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 007471113370815A

To protect you from hackers apt checks whether you are fetching the files from an authorized location. Therefore it needs to have a so called public key for this url which is missing here. You will have to fetch it from a trusted keyserver by its identification string. In this case it is 007471113370815A. Fetch the key by the following command:

gpg --keyserver keyserver.ubuntu.com --recv-keys 007471113370815A

The output should look as follows:

gpg: requesting key 3370815A from hkp server keyserver.ubuntu.com
gpg: key 3370815A: public key "Any url (Random Text) " imported
gpg: Total number processed: 1
gpg: imported: 1

  • If you get an error message like:

    ?: keyserver.ubuntu.com: Host not found

    try another Keyserver like wwwkeys.eu.pgp.net .

  • If you get an error message like:

    gpg: WARNING: unsafe enclosing directory permissions on configuration file `/home/yourusername/.gnupg/gpg.conf'
    gpg: external program calls are disabled due to unsafe options file permissions
    gpg: keyserver communications error: general error
    gpg: keyserver receive failed: general error

    The permissions of your public key directory are set in a potential vulnerable manner. This can easily occur when you changed permissions inside your home folder recursively. Fix this by (adjust to your user's name and group):

    sudo chown -R yourusername.yourusergroup /home/yourusername/.gnupg/
    sudo chmod 700 /home/yourusername/.gnupg/
    sudo chmod -R 600 /home/hanke/.gnupg/*

  • The error message

    gpg: WARNING: unsafe ownership on configuration file `/home/hanke/.gnupg/gpg.conf'

    usually pops up when you tried to execute gpg as root, after the su command or with sudo. Just do it as simple user.
Afterwards add your key:

gpg --armor --export 007471113370815A | sudo apt-key add -

The output should be:


You should now be able to run sudo apt-get update properly.