gpg: keyserver receive failed: No dirmngr

While trying to receive keys in my Debian Stretch server, I get this error:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
Executing: /tmp/apt-key-gpghome.4B7hWtn7Rm/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.4B7hWtn7Rm/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

Installing the package dirmngr fixed the error.

user@debian-server:~$ sudo apt-get install dirmngr

Retrying :

user@debian-server:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
Executing: /tmp/apt-key-gpghome.haKuPppywi/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: key A6A19B38D3D831EF: public key "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
Answered By: Hunter.S.Thompson

I wasn’t able to get dirmngr to work, but you can also just import the key directly using apt-key add. The GPG public key is often listed at the root of the repo like http://origin-download.mono-project.com/repo/

curl https://origin-download.mono-project.com/repo/xamarin.gpg | sudo apt-key add -
Answered By: Greg Bray

As said, the dirmngr package should be installed, but it may happen that apt does not work and cannot install any package.
Don’t worry. Search dirmngr package on https://packages.debian.org selecting your distribution version, download it on the linux machine and install it using dpkg command, for example:

cd /tmp
wget http://ftp.it.debian.org/debian/pool/main/g/gnupg2/dirmngr_2.1.18-8~deb9u4_amd64.deb
sudo dpkg -i dirmngr_2.1.18-8~deb9u4_amd64.deb

Then you’ll be able to run apt-key command to fetch the missing keys.

Answered By: Paolo Subiaco
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.