Installing from PPAs behind a proxy

Scenario:
You are building a Dockerfile or trying to run apt-get at work, but the network policy is blocking both direct access to the keyserver and through a correctly-configured proxy.

Let's say we're trying to install mono, which has the following instruction - but it hangs inexplicably.

sudo apt-key adv --keyserver \
hkp://keyserver.ubuntu.com:80 \
--recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Take note of the key specified in --recv-keys, this is the part we need to copy/paste into the next steps.

The work-around (tl;dr):

  • Step 1: Log into a computer in the free world (VPN/tunnel/mobile-hotspot/open WiFi network etc).

  • Step 2: Export the key to a text file.

  • Step 3: Copy the contents of the file across to the machine, and import it.

Step 1:

$ export keyid=3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
$ gpg --keyserver keyserver.ubuntu.com --recv $keyid && gpg --export --armor $keyid > key.txt

gpg: requesting key D3D831EF from hkp server keyserver.ubuntu.com
gpg: key D3D831EF: "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

Alter the value of keyid as per your needs

Step 2

The file key.txt can now be copied across to your locked-down machine by email, copy/paste, etc into a file named key.txt.

Step 3

cat key_file | sudo apt-key add -

If you are doing this inside a Dockerfile, then you could use the ADD command to put the key in /tmp/.

Now continue with the rest of the instructions and the apt-repository will now be accepted by the system.

Alex Ellis

Read more posts by this author.

Subscribe to Alex Ellis' Blog

Subscribe to keep in touch. By providing your email, you agree to receive marketing emails from OpenFaaS Ltd

or subscribe via RSS with your favourite RSS reader

Learn Go with my new eBook

eBook cover

"Everyday Go" is the fast way to learn tools, techniques and patterns from real tools used in production based upon my experience of building and running OpenFaaS at scale.

Buy a copy on Gumroad