Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

apt: NO_PUBKEY and signatures couldn't be verified

The repository key is missing, expired or unpinned. Fetch the vendor key into a dedicated keyring and reference it with signed-by.

~5 min readLinux
#linux#apt#gpg#packaging
Bold white headline reading NO PUBKEY with an apt repository crate holding an amber missing key slot beside a cyan keyring.

Introduction & Quick Summary

apt update on a fresh server ends with a wall of warnings, and one repository is skipped:

code
W: GPG error: https://download.docker.com/linux/ubuntu jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 E: The repository 'https://download.docker.com/linux/ubuntu jammy InRelease' is not signed.

Quick answer: the repository's signing key is missing from the keyring that its source entry points at. Fetch that one key, store it in a dedicated keyring file, and pin the entry to it with signed-by.

sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg

The key ID in the message is the fingerprint's last 16 hex digits. NO_PUBKEY means the key is absent; EXPKEYSIG means it is present but expired; BADSIG means the signature does not match the key you have. Each has a different repair, and reinstalling the key fixes only the first.

The three parts to check are: the source line (which repository and which signed-by file), the keyring file (does it exist, does it contain that fingerprint), and the key's validity dates.

Core Mechanics, Signatures & Reproducible Setup

Inspect what the system believes before changing anything:

bash
grep -r "download.docker.com" /etc/apt/sources.list /etc/apt/sources.list.d/ ls -l /etc/apt/keyrings /etc/apt/trusted.gpg.d sudo gpg --show-keys --with-fingerprint /etc/apt/keyrings/docker.gpg sudo apt-get update -o Debug::Acquire::gpgv=true 2>&1 | tail -20

A modern source entry names its keyring explicitly:

deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable

An older one relies on global trust: any key in /etc/apt/trusted.gpg or /etc/apt/trusted.gpg.d/ may sign any repository. That is convenient and weaker, which is why Debian and Ubuntu moved to per-repository keyrings and the signed-by field.

Error tokenMeaningFix
NO_PUBKEY 7EA0A9C3F273FCD8key absent from keyringimport the key into the pinned file
EXPKEYSIGkey present, past expiryrefresh the key from the vendor
KEYEXPIREDsame, as a reason stringrefresh or replace the repository key
BADSIGsignature does not verifywrong or corrupted key, re-download
is not signedapt refused the reporesolve the GPG warning above
404 Not Foundwrong codename or suitefix the distribution name, not the key

Key Comparison Table

Storage locationReferenced howScopeStatus
/etc/apt/keyrings/<name>.gpgsigned-by= in the entryone repositorycurrent best practice
/etc/apt/trusted.gpg.d/<name>.gpgglobal, all repositoriesevery repositorylegacy, still works
/etc/apt/trusted.gpgglobal binary keyringevery repositorylegacy, avoid
/usr/share/keyrings/<name>.gpgsigned-by=package-managed keyfor distro packages
apt-key addglobalevery repositorydeprecated, removed in newer releases

Which import command to use:

SituationCommandNote
Vendor serves an ASCII-armored keypipe it into gpg --dearmor -o file.gpg.gpg binary is what apt expects
Vendor serves a binary keycurl -fsSL URL -o file.gpgcheck with file
Key ID known, vendor URL unknowngpg --keyserver hkps://keyserver.ubuntu.com --recv-keys IDexport to the keyring file afterwards
Key already in another keyringexport it, then gpg --dearmor -o new.gpgkeeps the fingerprint
Keyservers blocked by firewalldownload the key from the vendor's sitekeyserver traffic uses port 11371

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Read the source line and pin the key

# 1. which entry produced the error grep -rn "docker.com" /etc/apt/sources.list.d/ # 2. fetch the key into a dedicated file sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg # 3. rewrite the entry with signed-by echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update

Print the fingerprint and compare it with the vendor's published value. A key that verifies but belongs to someone else is worse than no key at all:

bash
gpg --show-keys --with-fingerprint /etc/apt/keyrings/docker.gpg | head -5

2. Verify the download before trusting it

curl -fsSL URL | gpg --dearmor fails silently into an empty file when the fetch returns a 404 page, and apt then reports NO_PUBKEY again. Check the file is a key:

bash
file /etc/apt/keyrings/docker.gpg # GnuPG keybox or OpenPGP public key ls -l /etc/apt/keyrings/docker.gpg # non-zero size sudo gpg --show-keys /etc/apt/keyrings/docker.gpg | grep -E "pub|uid"

When the vendor publishes a SHA256 checksum of its key, compare it with the hash tool before installing. A truncated key gives BADSIG later, which is harder to diagnose.

3. EXPKEYSIG: the key exists but has expired

code
W: GPG error: https://packages.cloud.google.com/apt cloud-sdk InRelease: The following signatures were invalid: EXPKEYSIG 3746C208A7317B0F

EXPKEYSIG does not mean the key is wrong, only that its Valid-Until date passed. Vendors usually publish a renewed key at the same URL, so re-downloading into the same file is the fix. If the URL still serves the expired key, look for a key-rotation notice on the vendor's install page and follow the new instructions, which often change the repository URL as well.

4. Migrating away from apt-key

# old style, still seen in many Dockerfiles curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add - # modern equivalent curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

apt-key writes to the global trusted keyring and is deprecated; on newer releases the command is gone, so scripts fail with apt-key: command not found. The migration is mechanical: one keyring file per repository, one signed-by per source entry. A host with both old and new entries for the same repository gets duplicate warnings and slower updates, so remove the old lines after migrating.

5. Containers and CI images

A Dockerfile that adds a repository but not its key fails at apt-get update:

dockerfile
RUN install -m 0755 -d /etc/apt/keyrings \ && curl -fsSL https://download.docker.com/linux/debian/gpg -o /tmp/docker.asc \ && gpg --dearmor -o /etc/apt/keyrings/docker.gpg /tmp/docker.asc \ && chmod a+r /etc/apt/keyrings/docker.gpg \ && echo "deb [signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" \ > /etc/apt/sources.list.d/docker.list \ && apt-get update && apt-get install -y docker-ce-cli \ && rm -rf /var/lib/apt/lists/*

Baking the key into the image layer makes the build reproducible. Fetching it at run time makes the image depend on the vendor's availability, and a rotated key breaks old images silently when they rebuild. Avoid --allow-unauthenticated in automation: it disables the exact protection that failed, and it is the one flag reviewers should reject.

6. Debugging a key that looks correct

bash
sudo apt-get update -o Debug::Acquire::gpgv=true 2>&1 | grep -iE "gpgv|keyring|signed-by" sudo gpgv --keyring /etc/apt/keyrings/docker.gpg /var/lib/apt/lists/partial/*InRelease 2>&1 | tail

The debug output names the keyring file apt actually used. If it shows /etc/apt/trusted.gpg while your entry says signed-by, the file is unreadable by the _apt user — a chmod 600 keyring produces exactly this. The a+r permission in the install command exists for that reason. Clear stale lists with sudo rm -rf /var/lib/apt/lists/* before retrying, so an old partial download is not reused.

Common Compilation/Runtime Mistakes & Version Gotchas

Pasting a keyserver command without verifying. apt-key adv --recv-keys installs whatever the keyserver returns for that ID into global trust. Confirm the fingerprint against the vendor's site.

Putting every key in /etc/apt/trusted.gpg. Any repository can then be signed by any of those keys. One keyring per repository keeps the trust boundary visible.

Using [trusted=yes] instead of fixing the key. It disables verification for that repository and hides later key problems until the repository is compromised.

Confusing a 404 with a key error. 404 Not Found for jammy means the vendor dropped that codename or the URL is wrong; adding keys changes nothing.

Forgetting arch= on multi-arch hosts. Without it, apt update warns that the repository has no Release file for arm64 on an amd64 host and the fix looks like a key problem but is an architecture mismatch.

Version notes. apt-key is deprecated since apt 2.1, and Debian 12 and Ubuntu 24.04 installations ship without working legacy examples, so newer guides use /etc/apt/keyrings exclusively. Ubuntu 24.04's apt also changed how it reports unsigned repositories from a warning to an error, so a script that ignored W: now fails at E:. The cURL builder helps reproduce the exact key download with the right redirect flags.

Reference material: apt-secure(8) and SecureApt.

Official references

primary documentation

The Linux documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Linux guides

More in Linux

All Linux guides

The guides filed next to this one in Linux, in library order.