37

I'm trying to install Mongodb on Ubuntu 12 but when I run this command:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

This returned the error below:

keyserver.ubuntu.com host not found  
gpgkeys: HTTP fetch error 7: couldn't connect: no such file or directory  
gpg:no valid openPGP data found  
gpg: Total number processes :0 

I turned off Firewall on Iptables, but it don't work. Is there any idea?

Donald Duck
  • 2,473
  • 10
  • 29
  • 45
nyamka
  • 371
  • 1
  • 3
  • 3
  • Can your system resolve keyserver.ubuntu.com as an IP address? I.e, what's the output of `dig keyserver.ubuntu.com`? – Xyon Jul 17 '13 at 14:36

7 Answers7

43

This may not actually be a problem with looking up the keyserver, which is what the error suggests. The apt-key command calls gpg, which in turn tries to access the keyserver. Apparently there's a bug in gpg whereby if the keyserver doesn't have the key you are requesting, then gpg misinterprets that as "host not found".

It may well be that a non-responsive keyserver will do the same thing, and I have seen environments where the keyservers are blocked (corporate firewall rules), so that could be your root cause if there is an upstream firewall you do not have access to.

Just for reference, the key is there and the keyserver is currently responding for me:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.rh1myoBdSE --trustdb-name /etc/apt//trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: "Richard Kreuter <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

It may be that the port is the issue (it was the last time when I hit a corporate firewall problem), so try doing this on the standard HTTP port (80) instead, see if that sorts things out:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Manuel Jordan
  • 269
  • 5
  • 15
Adam C
  • 2,735
  • 21
  • 27
  • 5
    "doing this on the standard HTTP port (80) instead" is nice tricky! tks – Bill.Zhuang Jan 16 '17 at 07:17
  • 2
    Warning: without SSL, you could potentially be hit by a [MitM attack](https://en.wikipedia.org/wiki/Man-in-the-middle_attack) that serves you a key whose fingerprint has the same final eight characters ([example attacking key](https://keyserver.ubuntu.com/pks/lookup?search=0x7F0CEB10&op=vindex)). Such a key may not even be shared publicly, so you'd never know you were pwned. To prevent such an attack from publicly shared keys, [Debian's keyserver](https://keyring.debian.org/) has a policy stating “only keys in the Debian keyrings … will be returned by this server” – Adam Katz Jan 04 '19 at 20:49
24

I faced the same issue as my machine is behind a corporate proxy. Adding the gpg --keyserver-option http-proxy made the trick. Looks like:

sudo apt-key adv --keyserver-options http-proxy=<myProxy> --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Doktoro Reichard
  • 5,390
  • 5
  • 35
  • 42
fgungnir
  • 341
  • 2
  • 2
24

If you are using a proxy, for example company's proxy then probably the only way is to enter this manually, which is pretty straight forward. Run:

sudo apt-get update

and get the id of the pub_key. Then go to http://keyserver.ubuntu.com/ and search for the key as a hexidecimal, for example if the key is 7936A783B, then search for 0x7936A783B. Click on the pup link and copy the keys content and save it to a txt file. Go to terminal and navigate to the file and run:

sudo apt-key add key.txt

If it works, you will get a simple OK feedback. When all keys are added, then you may run:

sudo apt-get update

and there you have it!

DKo
  • 381
  • 2
  • 3
  • 3
    This is neat; it's also possible to use the URL you obtain verbatim with `apt-key` as follows: `apt-key adv --fetch-keys http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xD6ACA1C817B18ABC` – sxc731 Feb 25 '17 at 11:16
  • 2
    @sxc731 – The `apt-key` man page says: “Note that there are no checks performed, so it is easy to completely undermine the apt-secure(8) infrastructure if used without care.” This means you _really_ don't want to do that without SSL. Change that to `--fetch-keys https://…` and you should be reasonably safe. – Adam Katz Jan 03 '19 at 23:21
  • @AdamKatz very good point, thanks. Unfortunately I can't edit my comment to apply your suggestion but upvoted anyway... – sxc731 Jan 04 '19 at 10:07
  • The `--fetch-keys` option failed for me with error: `https://keyserver.ubuntu.com/pks/lookup?op=get gpgkeys: protocol `https' not supported gpg: no handler for keyserver scheme `https' gpg: WARNING: unable to fetch URI https://keyserver.ubuntu.com/pks/lookup?op=get: keyserver error` – miguelmorin Jan 16 '19 at 11:22
  • Thanks, exactly what I was looking for. – Miguel Ortiz May 09 '19 at 20:04
1

Correct: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv FDC247B7

Wrong: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key FDC247B7

MC10
  • 9,564
  • 4
  • 37
  • 52
d0lla
  • 11
  • 1
0

The second approach mentioned in this link worked for me. Manually download the key and add it. The link provides step by step procedure to fix the error happening due to missing key.

Aniket Thakur
  • 1,185
  • 10
  • 9
-1

DO not waste your time in searching...

it is just 2 step procedure:

follow the below link it should work:

http://naveenubuntu.blogspot.com/2011/08/fixing-gpg-keys-in-ubuntu.html

navin
  • 1
-4

The command below will help you.

curl -s https://keybase.io/heftig/pgp_keys.asc/\?fingerprint\=a2ff3a36aaa56654109064ab19802f8b0d70fc30 | gpg --import gpg --lsign 3B94A80E50A477C7

Kele Huang
  • 17
  • 2
  • 2
    How does this help? Seems to me to be very dangerous to import keys from a random source on the internet. – Colin 't Hart May 13 '21 at 08:03
  • This import a definitely useful PGP signature, which is posted here "https://aur.archlinux.org/packages/linux-fix_navi_reset/". – Kele Huang May 13 '21 at 09:14