Blog/ How to add an Ubuntu apt-get key from behind a firewall

By neerav.mehta Fri, 05/01/2015 - 21:30 1 Comments

Have you ever tried to install an apt package from a third-party repository from behind a firewall? If you run apt-key command with a key server, firewall will block it. Read this post to find out how to get past the firewall to import key for a third-party apt package.

Apt-get package management uses public key cryptography to authenticate downloaded packages. Each time you add another apt repository to /etc/apt/sources.list, you'll also have to give apt its key if you want apt to trust it. This can easily be done using apt-key command with as keyserver. Here is an example which imports key for Percona XtraDB:

sudo apt-key adv --keyserver --recv-keys 1C4CBDCDCD2EFD2A

This command contacts the server which in trun redirects to one of umpteen servers which are hosting the key. Behind a firewall, this external request will get blocked. An easy solution to this problem is to import the key manually. Here are the steps to do so:

1) Go to In the "Search String" textfield, enter the key you want to import. In my case, I entered "1C4CBDCDCD2EFD2A" as shown below. Press "Search".

2) If your key is found, you will see a screen with links to it as shown below.

Click on the link in the "pub" section as shown above. You will see the actual key:

3) Copy the key (marked in blue background in the above screenshot) and paste in a file named "keyfile" (you can choose any filename). Now execute the following commands:

sudo apt-key add keyfile
suao apt-get update

Voila! Your key should get imported and now you can proceed with software installation using apt-get install.

Ready to get Started?