How to manually add a public PGP key to Ubuntu’s Advanced Packaging Tool (APT)

I was trying to install docker on my Ubuntu server as an initial step to set up a continuous integration server for my Python project. As I was following through the guide provided by docker, the following command:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

gave me the following error:

gpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.net
gpg: keyserver timed out
gpg: keyserver receive failed: keyserver error

I did a ping afterwards and affirmed that my server was not able to reach the key server at p80.pool.sks-keyservers.net.

Since I was not able to add the PGP public key of docker's apt repository, I was not able to continue with the apt-get update command further down the guide.

Looking for the PGP public key of docker's apt repository server at p80.pool.sks-keyservers.net

Since I was not able to get the PGP public key automatically with the apt-key command inside my Ubuntu server, I thought about trying to add the key manually on my Ubuntu server.

I first tried to use my browser on my Windows machine to access the url specified by the --keyserver flag of the apt-key command. With that, I got to know that there is a web server running at p80.pool.sks-keyservers.net.

My browser returned me a web page with a search box and two buttons - "Search Key" and "Submit Key". Since I wanted to get the contents of the public PGP key of docker's apt repository, I typed "docker" into the search box, hit the "Search Key" button and was returned with a list of PGP public keys. And since I had indicated 58118E89F3A912897C070ADBF76221572C52609D via the --recv-keys flag in the apt-key command, I get my browser to find the section that contains the string "5811".

Indeed, there were some results and my browser highlighted the portion containing the "5811". I click on the first link in the section that contains "Fingerprint=5811 8E89 F3A9 1289 7C07 0ADB F762 2157 2C52 609D" and was returned with a page that displays the PGP public key that I was looking for.

Creating a physical file of the public PGP key

I then proceeded to create a physical file in my Ubuntu server via the vi editor. Note that the display page contains text that was irrelevant for the apt-key command. The PGP public key consists of only the following chunk:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.1.5+
Comment: Hostname: aes.keys.peer.sh

mQINBFWln24BEADrBl5p99uKh8+rpvqJ48u4eTtjeXAWbslJotmC/CakbNSqOb9oddfzRvGV
eJVERt/Q/mlvEqgnyTQy+e6oEYN2Y2kqXceUhXagThnqCoxcEJ3+KM4Rm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JRl90U/WDv/6cmfI08GkzDYBHhS8UL
WRFwGKobsSTyIvnbk4NtKdnTGyTJCQ8+6i52s+C54PiNgfj2ieNn6oOR7d+bNCcG1CdOYY+Z
XVOcsjl73UYvtJrO0Rl/NpYERkZ5d/tzw4jZ6FCXgggA/Zxcjk6Y1ZvIm8Mt8wLRFH9Nww+F
VsCtaCXJLP8DlJLASMD9rl5QS9Ku3u7ZNrr5HWXPHXITX660jglyshch6CWeiUATqjIAzkEQ
om/kEnOrvJAtkypRJ59vYQOedZ1sFVELMXg2UCkD/FwojfnVtjzYaTCeGwFQeqzHmM241iuO
mBYPeyTY5veF49aBJA1gEJOQTvBR8Q==
=Fm3p
-----END PGP PUBLIC KEY BLOCK-----

After I saved the file on my Ubuntu server as 58118E89F3A912897C070ADBF76221572C52609D.key in my current working directory, I proceeded to add it into the APT key store on my Ubuntu server.

The command to manually add the public PGP key of docker's apt repository at Ubuntu's Advanced Packaging Tool key store

With everything in place, I ran the following command:

sudo apt-key add 58118E89F3A912897C070ADBF76221572C52609D.key

The command returns the string "OK" and I was able to continue with the installation of docker-engine on my Ubuntu server.

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.