I am trying to add an external repository inside the yum.repos.d directory. The packages and metadata for that repository are signed with a gpg key. In case it's relevant, I'm on CentOS 7.2

So far as I can tell, the traditional way to set up the repository is to include a link to the gpg key inside the repository file.

That is, the file example.repo inside /etc/yum.repos.d contains the line:

gpgkey = https://example.com/repo/key

Then if you run yum update, you get a [y/N] prompt to import the GPG key, and if instead you run yum -y update the key gets imported automatically. So far so normal.

As an experiment, I tried removing the gpg-key download link from the repo file, and instead adding the key manually.

wget -O key https://example.com/repo/key
rpm --import key
and verify with
rpm -qa gpg-pubkey*

My expectation was that this would enable yum update to go through without raising the [y/N] prompt. But it didn't work - I still got the prompt asking me to import the key which I already imported. I tried in addition, removing the gpgkey entry from the repo file, but in that case yum update simply threw an error (since I also have gpgcheck = 1 and repo_gpgcheck = 1).

Why does this matter? Well, it seems to me that if you want to automate this process, then you are required to trust the https transport through which the key is downloaded. That's fine, but then the GPG key is not really adding any security, beyond verifying that the package downloaded properly.

In short, I think either I'm missing a trick to make yum recognize that I already imported the key, or the GPG keys really aren't adding much beyond plain old https. Any clues?

  • That prompt will only show up once. After you tell it 'y', it will not ask about that repo again. It does this on every new installation I've ever encountered. – Sokel Jan 14 '17 at 1:50
  • True - I'm referring to the situation where you're looking at automating the whole thing. – SauceCode Jan 14 '17 at 1:55
  • Thanks @SauceCode and @davor-cubranic for posting. Every other article suggests that if you do rpm --import key you'll be fine. After digging, I can see that after you run Davor's yum command or type "Y" to accept, a directory is created: /var/lib/yum/repos/<arch>/<class>/<reponame>/gpgdir. It contains a GPG public keyring and trustdb which yum uses to verify trust. Anyway, thanks again for this question & solution! – Liczyrzepa Sep 19 '18 at 15:52

According to the yum.conf man page, gpgkey is used to check the packages, while repo_gpgkey is used for checking the repository metadata. AIUC, the default is 0, but I still run into it. This is a cargo-cult workaround that seems to work for automating it:

yum -q makecache -y --disablerepo='*' --enablerepo=THENEWREPO
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.