Magic strings for people searching the archives to be able to find this:
$ gpg --keyserver ... --recv 0x...
gpg: keyserver receive failed: Connection refused
or
$ gpg --keyserver ... --recv 0x...
gpg: keyserver receive failed: No keyserver available
The problem is with dirmngr (a new component of gnupg2 responsible for
interacting with keyservers) failing DNS lookups. More information at
[1].
A workaround is to put "standard-resolver" in ~/.gnupg/dirmngr.conf &
restart dirmngr:
$ cat > ~/.gnupg/dirmngr.conf <<EOF
no-dirmngr
EOF
$ pkill dirmngr # maybe `sudo pkill dirmngr` if you were trying to use
apt-key or something
Or, you can use more recent gpg packages from debian testing where
this is already fixed. See e.g. [2], but be careful as mixing packages
between releases is not generally advisable.
Hope this saves someone some time.
[1]:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=849845
[2]:
https://serverfault.com/questions/22414/how-can-i-run-debian-stable-but-install-some-packages-from-testing