Sub topic 3
Repositories and signature verification
This chapter assumes you can use a Linux shell and sudo, know what a package is, and have SSH access to a Debian/Ubuntu or RHEL-family test machine. It covers where apt and dnf get packages, how they decide to trust them, and the errors you will meet when that trust check fails.
What a repository is
A repository (repo) is a web or file server that holds package files plus an index describing them. The index is called metadata. It lists every package name, version, dependency, size and checksum.
apt and dnf never browse the package files directly. They download the metadata first, work out what can be installed or upgraded, and only then fetch the package files they need. The next chapter covers refreshing metadata. Here the focus is on the trust model.
A typical server uses several repos at once:
- The distribution's main repo, which holds the base system.
- A security or updates repo, which holds fixes released after the base release.
- Optional extra repos, such as a vendor repo for nginx, PostgreSQL or Docker.
Each extra repo is another party you trust to run code as root on your server. Package install scripts run with root privileges, so adding a repo is a security decision.
The trust chain
Both tools use the same idea. A publisher signs with a private key, and your server holds the matching public key. If the signature checks out, the data was produced by the key holder and was not altered in transit.
The two ecosystems apply this chain at different points.
| Aspect | Debian/Ubuntu (apt) | RHEL-family (dnf) |
|---|---|---|
| What is signed | The repo metadata (Release file) | The metadata (optional) and each .rpm package |
| Package integrity | Checksums in signed metadata | Signature inside every .rpm, plus checksums |
| Repo definitions | /etc/apt/sources.list and /etc/apt/sources.list.d/ | /etc/yum.repos.d/*.repo |
| Key storage | /etc/apt/keyrings/ or /usr/share/keyrings/ | /etc/pki/rpm-gpg/ and the RPM key database |
| Setting that controls checking | `signed-by` per repo | `gpgcheck`, `repo_gpgcheck` per repo |
The key difference: apt trusts the signed metadata, and the metadata vouches for each package through checksums. dnf can additionally check a signature on each individual package file, so a package keeps its proof of origin even after you copy it elsewhere.
Repositories on Debian and Ubuntu
apt reads repo definitions from two places. The older one-line format lives in /etc/apt/sources.list and *.list files. Newer releases (Debian 12 and later, Ubuntu 24.04 and later) use the deb822 format in *.sources files, which is a block of fields.
cat /etc/apt/sources.list.d/ubuntu.sourcesA deb822 entry on Ubuntu looks like this:
Types: deb
URIs: http://security.ubuntu.com/ubuntu
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpgThe fields mean:
Typesisdebfor binary packages anddeb-srcfor source packages.URIsis the server address.Suitesis the release name plus a pocket, such asnoble,noble-updatesornoble-security.Componentsare subsets of the archive, such asmainanduniverse.Signed-Bynames the key allowed to sign this repo.
The Signed-By field limits which key can vouch for that one repo. This is better than the old model, where a key added to a global keyring could vouch for every repo on the machine.
Adding a third-party repo the current way
The legacy apt-key add command is deprecated because it put every key into one global trust store. Instead, store each key as a separate file and point to it from the repo definition.
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://example.com/repo/key.asc | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
sudo tee /etc/apt/sources.list.d/example.sources >/dev/null <<'EOF'
Types: deb
URIs: https://example.com/repo/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg
EOF
sudo apt updateexample.com is a placeholder. Use the vendor's documented URL, and compare the key fingerprint with the one the vendor publishes through a second channel before you trust it.
gpg --show-keys --fingerprint /etc/apt/keyrings/example.gpgRepositories on RHEL-family systems
dnf reads .repo files in /etc/yum.repos.d/. Each file contains one or more repo sections.
dnf repolist
dnf repolist --alldnf repolist shows enabled repos. --all also shows disabled ones.
A typical repo file looks like this:
[example]
name=Example vendor repository
baseurl=https://example.com/repo/rpm/$releasever/$basearch/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://example.com/repo/RPM-GPG-KEY-exampleThe important settings:
enabled=1turns the repo on.gpgcheck=1makes dnf verify the signature on each package.repo_gpgcheck=1makes dnf also verify the signature on the metadata. Not all vendors sign metadata, so check before enabling it.gpgkeyis where dnf imports the public key from on first use.$releaseverand$basearchare variables that dnf fills in with your release and CPU architecture.
On first use of a repo, dnf shows the key's fingerprint and asks you to confirm importing it. Read the fingerprint. That prompt is the moment where you decide to trust the publisher.
rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n'This lists the keys that rpm currently trusts.
Verifying a package by hand
You can check a downloaded rpm yourself:
dnf download nginx
rpm --checksig nginx-*.rpmA good result ends with digests signatures OK. An rpm for which the key is missing reports (MISSING KEYS) or NOKEY.
On Debian systems, dpkg packages usually have no per-file signature. To inspect a package's origin, ask apt which repo supplies each version:
apt-cache policy nginxThe output lists each candidate version with its repo and a priority number. The *** marks the installed version.
Common errors
These are the failures you will see most often. Each one is the system doing its job, so do not work around the error before you understand it.
| Message | Cause | Fix |
|---|---|---|
| `NO_PUBKEY ABCD1234` or `The following signatures couldn't be verified` | apt has no key for this repo, or `Signed-By` points to the wrong file | Install the correct key file and check the `Signed-By` path |
| `EXPKEYSIG` or `KEYEXPIRED` | The publisher's key expired | Fetch the vendor's renewed key and replace the old file |
| `The repository ... is not signed` | The repo has no signature | Do not bypass it. Ask the vendor, or stop using the repo |
| `GPG check FAILED` (dnf) | A package signature does not match any imported key | Confirm you imported the right key. A mismatch can also mean a damaged download |
| `Public key for ... is not installed` (dnf) | The key was never imported | Import the vendor key after checking its fingerprint |
| `Failed to download metadata for repo` | Network problem, wrong URL, or the release is end of life | Test the URL with `curl -I` and check the `$releasever` value |
Mirrors and HTTPS
Distributions spread load across many mirrors, servers run by universities and companies. You do not need to trust a mirror, because signatures protect the content no matter who serves it. Plain HTTP is therefore acceptable for official distribution repos, and signed metadata still protects you. HTTPS adds privacy and protects against some downgrade and replay situations, so prefer it for third-party repos.
One limit applies: signatures prove who published the data, not that the data is safe. A signed package from a repo you trust can still contain a bug. The signature also does not by itself stop an attacker from replaying old, validly signed metadata. apt metadata carries a Valid-Until date in some repos to limit this.
A short review routine
Before you add or keep any repo on a server:
- Confirm who runs the repo and why the server needs it.
- Check the key fingerprint through a second channel.
- Keep
gpgcheck=1(dnf) and a per-repoSigned-By(apt). - Remove repos you no longer use. List them with
dnf repolist --allorgrep -r '^URIs\|^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/. - Check the repos again after every release upgrade, since third-party repos often get disabled or break.
Exercise
A colleague says that apt update prints "NO_PUBKEY" for a new vendor repo, and suggests adding [trusted=yes] to the repo line so the warning goes away. What do you recommend instead, and why?
Show answer
Do not use trusted=yes, because it switches off signature checking for that repo and lets any tampered package install as root. Instead, download the vendor's public key, check its fingerprint against one published through a separate channel (for example, the vendor's documentation site), save it under /etc/apt/keyrings/, and reference it with Signed-By in the repo's .sources file. Then run sudo apt update again.
Exercise
On a RHEL-family server, what is the difference between gpgcheck=1 and repo_gpgcheck=1 in a .repo file, and what does rpm --checksig package.rpm tell you?
Show answer
gpgcheck=1 makes dnf verify the signature inside each downloaded package file. repo_gpgcheck=1 makes dnf verify the signature on the repo metadata. rpm --checksig checks the digests and signature of one rpm file against the keys in the rpm database. A result ending in "digests signatures OK" means the package is intact and signed by a trusted key. A NOKEY or MISSING KEYS result means the key has not been imported.