I recently installed Ubuntu 17.04 and I'm not able to add any ppa.
I tried to manually add keys using different keyservers but on every attempt I'm getting keyserver received error:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0F164EEB

Error Received:

Executing: /tmp/apt-key-gpghome.qm2WNA0lTK/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0F164EEB
gpg: keyserver receive failed: No keyserver available

$ sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 0F164EEB

Error Received:

Executing: /tmp/apt-key-gpghome.O681PzEx7r/gpg.1.sh --keyserver keys.gnupg.net --recv-keys 0F164EEB
gpg: keyserver receive failed: Connection refused

It is the same case with other keys. I'm not able to add any PPA.


11 Answers 11


I was getting the same 'gpg keyserver connection refused' error with gpg at the command line, GPA, and KGpg. I am using gnupg 2.1.18-8 on Debian Sid. I enabled debugging in dirmngr as follows:

sudo pkill dirmngr; dirmngr --debug-all --daemon --standard-resolver

The debugging output on the console complained about the lack of a Tor connection. It turned out that "use-tor" was enabled in $HOME/.gnupg/dirmngr. (Thanks, gpgconf!) I commented it out, leaving an empty dirmngr.conf, and keyserver communications are now working normally.

  • 4
    Just sudo pkill dirmngr solved my issue.
    – BcK
    Dec 4, 2019 at 20:04
  • The additional output from this lead me to another answer here that fixed it for me (on Arch-based Manjaro, despite being on AskUbuntu, answer also mentions Arch). Aug 27, 2020 at 11:11

This also happened to me when something was wrong with the DNS resolution setup. Check that there are nameservers listed in /etc/resolv.conf (also, try alternative nameservers). If you are using systemd-resolved, then make sure that /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf.


This error can also be caused if you retrieve gpg keys through tor & tor is not running.

In your system log you will see:

command 'KS_GET' failed: No keyserver available

To retrieve keys through tor set in ~/.gnupg/dirmngr.conf:

# https://gnupg.org/blog/20151224-gnupg-in-november-and-december.html
keyserver hkp://jirk5u4osbsr34t5.onion

# https://sks-keyservers.net/overview-of-pools.php#pool_hkps
hkp-cacert /etc/ssl/CA/sks-keyservers.netCA.pem

For those of you stuck on this error after trying the above solutions, make sure that you've included the hkp:// protocol prefix before the keyserver address.

This works for me:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0F164EEB

This didn't work for me:

apt-key adv --keyserver keyserver.ubuntu.com:80 --recv-keys 0F164EEB
  • This worked for me, just replace your key with mysql repo key from error it returns.
    – juslintek
    Mar 18 at 13:32

one of the cause is indeed a proxy issue see Unable to add gpg key with apt-key behind a proxy

you would have to use the following command:

$ sudo apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --keyserver-options http-proxy=http://myproxy:3128 --recv-keys 0F164EEB

...or a combination of curl+apt-key


For your information, I've encountered the same problem:

gpg: keyserver receive failed: Connection refused

My resolv.conf contained:

nameserver XXX.XXX.XXX.XXX
search XXX.XXX

and was immutable:

$ lsattr /etc/resolv.conf
----i---------e---- /etc/resolv.conf

Furthermore, I didn't have a DNS server bound to the loopback network interface (

So, when I tried to execute this command

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXXXXXX

apt-key only used the first nameserver that doesn't exist and failed.

I removed the immutability:

sudo chattr -i /etc/resolv.conf

I modified the first nameserver to point to a working one.

And I put the immutability back:

sudo chattr -i /etc/resolv.conf

And finally apt-key worked.


SOLUTION(?): Getting same "no keyserver available" error on Parrot Security 3.6.

Used GPA v0.9.10 (Gnu Privacy Assistant).

  1. Click "Server" -> "Retrieve Keys"
  2. Enter , in your case 0F164EEB.
  3. Click "OK". Wait a bit.

If it works, you will have an entry in the "Key Manager" listing. I was able to continue with verification process from there.


Try this:

  • Step 1: Before running curl, you may want to open this directly in your browser, to check if it does exist and downloadable. 0x0F164EEB is the key you're looking for. https://keyserver.ubuntu.com/pks/lookup?search=0x0F164EEB&fingerprint=on&op=get

  • Step 2: The below either command will download the specific pub-key into target_pubkey.pgp.

    • http-proxy: If you're behind a http-proxy such as in a company or collage network, and have difficulty accessing anything ports other than 80 or 443.
      curl -x http://proxy:port -O target_pubkey.pgp https://keyserver.ubuntu.com/pks/lookup?search=0x0F164EEB&fingerprint=on&op=get
    • socks-proxy: Or you have access to a socks-proxy, socks5h means the hostname is resolved remotely.
      curl -x socks5h://proxy:port -O target_pubkey.pgp https://keyserver.ubuntu.com/pks/lookup?search=0x0F164EEB&fingerprint=on&op=get
  • Step 3: Add the targeted key.
    sudo apt-key add target_pubkey.pgp

  • Step 4: Add the targeted repository.
    sudo add-apt-repository "deb https://your-targeted-repository targeted-project"

  • Step 5: Update.
    sudo apt-get update



sudo apt-get update

before you run

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0F164EEB

And if you have an "echo" line before that, run another sudo apt-get update even before that:

RUN apt-get update
RUN sh -c 'echo "..." > /etc/...'
RUN apt-get update
RUN apt-key adv ...

By this, I got rid of the similar error "Cannot assign requested address":

Executing: /tmp/apt-key-gpghome.Up2U8vHXpt/gpg.1.sh --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6
gpg: keyserver receive failed: Cannot assign requested address
ERROR: Service 'listener' failed to build: The command '/bin/sh -c apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6' returned a non-zero code: 2


Most likely: server is just busy, try again

The whole idea abobe is likely just a placebo since this answer to the same error, but in another context says that this can appear when the address is just busy. Which would mean: if you have this error, just try again, and sudo apt-get update might not change anything, then. That sounds most likely.


I was able to use keyserver.ubuntu.com from GnuPG only after adding a hkps:// prefix and a :443 suffix:

gpg2 --keyserver hkps://keyserver.ubuntu.com:443 --recv-keys XXXXXXXXXXXXXXXX

Replace gpg2 with apt-key adv in case you need to fetch a key for APT. In my case, I needed to import it into my user keyring for another purpose.

Thanks to Cyril Chaboisseau's answer for providing a hint.


My solution was:

  1. change DNS to primary, secondary DNS (local router)
  2. use gpg instead of apt-key which is now depreciated
  3. add protocol "hkp://" and port 80 to key server address
  4. reboot

cli command:

    sudo gpg  --keyserver hkp://pgp.mit.edu:80 --recv-keys 1C61A2656FB57B7E4DE0F4C1FC918B335044912E 
[sudo] password for rd: 
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key FC918B335044912E: public key "Dropbox Automatic Signing Key <linux@dropbox.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.