Download apt-get keys




en it

Did you ever have had to update your Debian box ( or Debian based box ) and, once you have added the repo that you have googled for days, you magically find yourself with a message like :

W:GPG error: http://ftp.debian-unofficial.org sid Release: The following signatures couldn’t be verified because the public key is not available:NO_PUBKEY 394D199524C52AC3

W: You may want to run apt-get update to correct these problems

well ... with a little bit of good luck and a couple of command lines the problem can be solved. Let's start with the command line, then we'll comment them .

gpg --keyserver subkeys.pgp.net --recv-keys <key>

gpg --armor --export <key> | sudo apt-key add -

Let's explain it .

The first command asks gpg to download the <key> that you're looking for, in the example 394D199524C52AC3, from a public key-server and to add it to your database if public keys .

The second line is composed of two commands linked together by a pipe (|) : export the <key> from the local database and import it,as root, in the apt key-database.

Easy uh ?

So easy that it can all be put up together in a script that one can call on the fly . How ? Well, you only need to replace <key> with $1 ( aka the first input parameter of the script).Use your preferred text editor ( mine is joe ) and create a file that contains the following code:

#!/bin/bash
gpg --keyserver subkeys.pgp.net --recv-keys $1
gpg --armor --export $1 | sudo apt-key add -

... yes, you are allowed to copy & paste ...

Now, save it with a name that's easy to remember ( eg. getAptKey ) and give it the right perms. :


chmod +x getAptKey

you have nothing left to do but a simple test !!

./getAptKey 394D199524C52AC3

Happy Update !!