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.

Introduction & Quick Summary
apt update on a fresh server ends with a wall of warnings, and one repository is skipped:
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.gpgThe 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:
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 -20A 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 token | Meaning | Fix |
|---|---|---|
NO_PUBKEY 7EA0A9C3F273FCD8 | key absent from keyring | import the key into the pinned file |
EXPKEYSIG | key present, past expiry | refresh the key from the vendor |
KEYEXPIRED | same, as a reason string | refresh or replace the repository key |
BADSIG | signature does not verify | wrong or corrupted key, re-download |
is not signed | apt refused the repo | resolve the GPG warning above |
404 Not Found | wrong codename or suite | fix the distribution name, not the key |
Key Comparison Table
| Storage location | Referenced how | Scope | Status |
|---|---|---|---|
/etc/apt/keyrings/<name>.gpg | signed-by= in the entry | one repository | current best practice |
/etc/apt/trusted.gpg.d/<name>.gpg | global, all repositories | every repository | legacy, still works |
/etc/apt/trusted.gpg | global binary keyring | every repository | legacy, avoid |
/usr/share/keyrings/<name>.gpg | signed-by= | package-managed key | for distro packages |
apt-key add | global | every repository | deprecated, removed in newer releases |
Which import command to use:
| Situation | Command | Note |
|---|---|---|
| Vendor serves an ASCII-armored key | pipe it into gpg --dearmor -o file.gpg | .gpg binary is what apt expects |
| Vendor serves a binary key | curl -fsSL URL -o file.gpg | check with file |
| Key ID known, vendor URL unknown | gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys ID | export to the keyring file afterwards |
| Key already in another keyring | export it, then gpg --dearmor -o new.gpg | keeps the fingerprint |
| Keyservers blocked by firewall | download the key from the vendor's site | keyserver 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 updatePrint 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:
gpg --show-keys --with-fingerprint /etc/apt/keyrings/docker.gpg | head -52. 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:
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
W: GPG error: https://packages.cloud.google.com/apt cloud-sdk InRelease:
The following signatures were invalid: EXPKEYSIG 3746C208A7317B0FEXPKEYSIG 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.gpgapt-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:
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
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 | tailThe 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 documentationThe Linux documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Linux guides
All Linux guidesnginx 502 Bad Gateway: upstream connection refused
The log line names the address and errno, which is the diagnosis. Fix the host, the start-up order, the buffers, or the timeout that actually fired.
Linux: Read-only file system (EROFS) on a mounted volume
EROFS is a mount condition, not a permission error. Read the kernel log first: I/O errors, a full thin pool, an ro fstab entry or a read-only root.
Linux: bind: Cannot assign requested address
EADDRNOTAVAIL means the kernel had no address to bind: too many TIME_WAIT sockets, an IP missing from the interface, or a wrong listen address.
systemd: Job for X.service failed because the control process exited
systemd only reports that the process exited non-zero. Read the status line, decode the status code and compare the unit's environment with your shell.
More in Linux
All Linux guidesThe guides filed next to this one in Linux, in library order.