Ubuntu – No gpg key from behind a firewall


Just stumbled over this closed thread here:
GPG Error while running apt-get

Same problem here, Ubuntu 12.04 behind a firewall and proxy.

I dont think that matter is duplicate of the given topic.
So i reopen this matter in this thread.

My output:

root@musik-Aspire-7741:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 58B98E87
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-  keyring /tmp/tmp.tWVMhyIMYh --trustdb-name /etc/apt/trustdb.gpg --keyring     /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver     hkp://keyserver.ubuntu.com:80 --recv-keys 58B98E87
gpg: Key 58B98E87 of hkp Server keyserver.ubuntu.com request
?: keyserver.ubuntu.com: Connection refused
gpgkeys: HTTP fetch error 7: couldn't connect: Connection refused
gpg: No valid OpenPGP data found.
gpg: Total number processed: 0

Conclusion: gpg is not working with hkp://keyserver.ubuntu.com:80 via http.

Best Answer

Behind proxy, environment variable http_proxy should be set. This can be done in either of the two ways.

1.Create apt.conf file in /etc/apt directory if not present and add the following line to it. Acquire::http::Proxy "http://user:password@server:port";
2.Simply set the environment variable using the following command from terminal.
export http_proxy=http://user:password@server:port

Finally a small tweak, add -E option to the command for the environment variables to be used as follows
sudo -E apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 58B98E87