Fixing ‘Failed to Download GPG Key for Repo’ Error in CentOS

centosmariadbyum

I installed MariaDB on a computer with CentOS using the instructions given here:

MariaDB Package Repository Setup and Usage – MariaDB Knowledge Base

The basic command I used was:

sudo yum install MariaDB-server MariaDB-client  

and I did not install Maxscale or percona.

MariaDB installation has compleetd successfully, but now if I enter a yet uninstalled command in the bash shell, I am getting this error:

Failed to search for file: Failed to download gpg key for repo 'mariadb-main': Curl error (37): Couldn't read a file:// file for file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY [Couldn't open file /etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY]

For example, if I enter the command ftp, previously I would have got a message indicating that ftp was not installed, and I would have got some recommendations on which command I meant and would like to download. However, now I get this:

[username@localhost ~]$ ftp
bash: ftp: command not found...
Failed to search for file: Failed to download gpg key for repo 'mariadb-main': Curl error (37):     Couldn't read a file:// file for file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY [Couldn't open file   /etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY]
[username@localhost ~]$

After some searching around I have found that it is because the file etc/yum.repos.d/mariadb.repo has an entry:

gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY    

and the MariaDB-Server-GPG-KEY file does not exist in etc/pki/rpm-gpg

I suppose this should have been created automatically when I installed mariadb? How do I make this bash error go away? Is there any way I can download or create this file manually?

— EDIT —
This was resolved as follows:

Downloaded RPM-GPG-KEY-MariaDB as explained in Philip's answer (https://unix.stackexchange.com/a/602962/28907)

Copied it to /etc/pki/rpm-gpg/

In /etc/yum.repos.d/mariadb.repo changed the line gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY to gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-MariaDB

Set the gpgcheck for other entries in the mariadb.repo file to 0 (I don't have maxscale and mariadb enterprise installed)

Best Answer

For me the solutions was to do manually

sudo wget https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

directly inside of directory /etc/pki/rpm-gpg/, and that created the file RPM-GPG-KEY-MariaDB.