I want to add new repositories on Ubuntu 18.04 and randomly get the following error:
gpg: keyserver receive failed: Cannot assign requested address
Randomly, as in, the same command sometimes works and sometimes doesn't. When it doesn't, I just rerun it and eventually it works.
I've seen related questions, like this one but there are no satisfactory solutions. I didn't have this problem is the last few weeks, so something must have changed. On my side I believe nothing has changed, there are no reports that the keyserver is down or degraded, so I'm at a loss...
To reproduce this issue using docker:
- Run
docker run -it --rm ubuntu:18.04
- In the docker container, run:
apt update && apt install gnupg2 -y
- Try to add the repository key, this one is from ROS Spanshot:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA, you may also try the key to Git PPA repository: apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A1715D88E1DF1F24
The last step often fails with:
Executing: /tmp/apt-key-gpghome.FhnZLWMBd1/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA
gpg: keyserver receive failed: Cannot assign requested address
But if I rerun the same command, it will eventually work and output:
Executing: /tmp/apt-key-gpghome.x0bEOm55IF/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA
gpg: key AD19BAB3CBF125EA: public key "ROS Spanshot builder <rosbuild@ros.org>" imported
gpg: Total number processed: 1
gpg: imported: 1