How to Fix GPG No Public Key NO_PUBKEY Error During apt-get Update

by Ramesh Natarajan on May 8, 2009

When executing the apt-get update command, you may get “There is no public key available” warning message. This article explains how to solve this warning message message.

$ apt-get update
Get:1 http://debian.linux.org.tw lenny Release.gpg [394B]
Get:2 http://debian.linux.org.tw lenny Release [73.6kB]
Get:3 http://debian.linux.org.tw lenny/main Packages [5310kB]
Fetched 5384kB in 1m13s (73.5kB/s)
Reading package lists... Done
W: There is no public key available for the following key IDs:
4D270D06F42584E6
W: You may want to run apt-get update to correct these problems

On ubuntu, the error message might look something like the following:

W: GPG error: http://debian.uchicago.edu etch Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9AA38DCD55BE302B

Solution for “There is no public key available for the following key ID”

To solve this problem, get the key using gpg command and add it to the local apt repository using apt-key add command as shown below:

$ gpg --keyserver wwwkeys.eu.pgp.net --recv-keys 4D270D06F42584E6

# You should see the following output while executing the above command.
gpg: Total number processed: 1
gpg:               imported: 1

$ gpg --armor --export 4D270D06F42584E6 | apt-key add -
OK

$ apt-get update
[Note: Now update will work without the key error message]

Solution template for “There is no public key available for the following key ID” problem

Please note that you may get the same error message for a different keys. Anytime you get a key missing issue, you should take that new key and add it as shown below using apt-key add.

$ keymissing= [missing-key] && \
gpg --keyserver wwwkeys.eu.pgp.net --recv-keys $keymissing && \
gpg --armor --export $keymissing | apt-key add - && \
apt-get update

 
For example, if it says missing key 4D270D06F42584E6, modify the above template to add the keymissing variable. i.e replace [missing-key] in the above template with 4D270D06F42584E6 as shown below.

$ keymissing=4D270D06F42584E6 && \
gpg --keyserver wwwkeys.eu.pgp.net --recv-keys $keymissing && \
gpg --armor --export $keymissing | apt-key add - && apt-get update

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 10 comments… read them below or add one }

1 David May 8, 2009 at 12:22 pm

Those keys are there for a reason, if you don’t have the key then you should find out why instead of just blindly installing it.
On a properly configured box (eg default) then all the keys should be there. If trusting everyone blindly was a good idea, then they wouldn’t bother signing them in the first place.

2 stat June 5, 2009 at 6:25 am

David – I have been using Ubuntu for many years and many versions the gpg issue has indeed become worse over the last couple of versions but all I have read indicates that this is an issue with the repos and not a localized problem. In researching through the bug tracker, googling the forums etc. I have frequently read that the gpg issue was not critical or indicative of a larger issue. I agree those keys are there for a reason and often do their job without even being noticed but any box that has been modified (third party sources and the like) are going to see these errors. Depending on what you have installed I can tell you what keys you will need. Apt keys and key ring are both still works in process and a bit error prone. I would not recommend freaking every time one of the acted up, you will be pretty busy.

If you have evidence to support that this is a serious issue or even can explain what the issue is so that it can be avoided it would be of help to the community. I would suspect that the only way to avoid this is to run a default system which would be missing the whole point of Linux. I fail to see that this is anything to worry about and appreciate Ramesh posting this here and reminding me of the solution (I have forgotten it so many times I have since embedded it into my sources list for reference).

3 Marko July 8, 2009 at 4:51 pm

Hi,
Just to say thank you for your e-Book Linux – 101 Hacks

Bye
Marko

4 Timbuktu September 5, 2009 at 1:27 pm

You need to add ‘sudo’ to the command apt-key… it should be:
gpg –armor –export $keymissing | sudo apt-key add – && apt-get update

otherwise, you get this error:
timbuktu@homecomp:~$ keymissing=F9A2F76A9D1A0061 && \
> gpg –keyserver wwwkeys.eu.pgp.net –recv-keys $keymissing && \
> gpg –armor –export $keymissing | apt-key add – && apt-get update
gpg: requesting key 9D1A0061 from hkp server wwwkeys.eu.pgp.net
gpg: key 9D1A0061: “Opera Software Archive Automatic Signing Key 2010 ” not changed
gpg: Total number processed: 1
gpg: unchanged: 1
gpg: no writable keyring found: eof
gpg: error reading `-’: general error
gpg: import from `-’ failed: general error

5 BartVB July 12, 2010 at 1:11 am

Most of the time it’s easier to fix these problems with:

# aptitude install debian-keyring debian-archive-keyring

This should install the required public keys.

6 worawit March 2, 2011 at 2:25 am

Thanks from Thailand.
my command is
# pgp –recv-keys AED4B06F473041FA
…..
# pgp –armor –export AED4B06F473041FA | apt-key add -
…..
# apt -get update

7 Eyal Peleg December 27, 2011 at 12:32 am

Lots of thatks to BartVB.
aptitude install debian-keyring debian-archive-keyring
worked great for me on debian lenny.

8 Chris March 6, 2012 at 11:40 pm

I got Y PPA Manager. There is an advanced button in the software that will try to find the missing keys. Worked for me.

9 Lee July 25, 2012 at 12:37 pm

You are doing too many steps.

Just run:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 4D270D06F42584E6

That downloads and adds the key

10 Anonymous January 12, 2013 at 2:28 am

Thanks BartVB!

Leave a Comment

Previous post:

Next post: