How to Fix the NO_PUBKEY GPG Error on apt update in Ubuntu
Learn how to fix the NO_PUBKEY GPG error on apt update in Ubuntu 24.04 with modern /etc/apt/keyrings signed-by methods and keyserver imports.

5 min read
Learn how to fix the NO_PUBKEY GPG error on apt update in Ubuntu 24.04 with modern /etc/apt/keyrings signed-by methods and keyserver imports.
- Prerequisites and Supported Releases
- Understanding the NO_PUBKEY Error Anatomy
- Method 1: Fetching Missing Keys Directly from Ubuntu Keyserver (Modern Standard)
The Advanced Package Tool (APT) verifies the cryptographic integrity of every downloaded package and repository manifest using public-key GPG cryptography.
When you add a third-party repository (such as Docker, NodeSource, Google Cloud, or PostgreSQL) without importing its corresponding cryptographic public key, APT halts with an error: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY [KEY_ID].
This error serves as a vital security shield preventing man-in-the-middle attackers from injecting malicious or tampered software binaries into your system.
Historically, administrators resolved this using apt-key adv; however, modern Ubuntu releases have completely deprecated apt-key because storing keys globally in /etc/apt/trusted.gpg allows third-party repositories to sign packages across all system repositories.
In this guide, we walk through how to fix the no_pubkey gpg error on apt update using modern, secure signed-by keyrings and automated keyserver queries.
Complete troubleshooting guide on diagnosing and resolving GPG signature verification failures (NO_PUBKEY and EXPKEYSIG errors) during apt update on Ubuntu 24.04 LTS and 22.04 LTS. Explains why legacy apt-key has been permanently deprecated, how to safely import missing public keys into /etc/apt/keyrings/ using curl and gpg --dearmor, and how to link signed-by repositories securely.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server or computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- An unprivileged user account with
sudoadministrative privileges. - Active internet access to communicate with Ubuntu keyservers.
- The exact 16-character hexadecimal GPG Key ID reported in your terminal error.
Understanding the NO_PUBKEY Error Anatomy
When you execute sudo apt update, APT downloads the InRelease or Release.gpg file from each repository.
If the signing key is not recognized in your local keyring, APT aborts with an error similar to this output:
Examine the structure of the verification error:
# Typical terminal error output during apt update:
# W: GPG error: http://ppa.launchpad.net/ansible/ansible/ubuntu noble InRelease:
# The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7FF49B32E90509E4
# E: The repository 'http://ppa.launchpad.net/ansible/ansible/ubuntu noble InRelease' is not signed.
# N: Updating from such a repository can't be done securely, and is therefore disabled by default.
Extracting the 16-Character Key ID
In the example above, the missing public key identifier is 7FF49B32E90509E4.
This 16-character hexadecimal string is the unique fingerprint identifier required to retrieve the public key from official keyservers.
Method 1: Fetching Missing Keys Directly from Ubuntu Keyserver (Modern Standard)
The modern security standard requires storing each repository's public key in an isolated binary keyring file inside /etc/apt/keyrings/.
Use gpg with the official Ubuntu keyserver (keyserver.ubuntu.com) to download and dearmor the public key directly into the secure keyrings directory:
Replace MISSING_KEY_ID with your specific hexadecimal key string:
# Ensure the secure keyrings directory exists with 755 permissions:
sudo mkdir -p /etc/apt/keyrings
sudo chmod 755 /etc/apt/keyrings
# Download and import key directly into an isolated keyring file:
# Replace 7FF49B32E90509E4 with your actual missing key ID:
gpg --keyserver keyserver.ubuntu.com --recv-keys 7FF49B32E90509E4
gpg --export 7FF49B32E90509E4 | sudo tee /etc/apt/keyrings/missing-repo.gpg > /dev/null
# Verify permissions (must be readable by _apt user):
sudo chmod 644 /etc/apt/keyrings/missing-repo.gpg
Method 2: One-Line Keyserver Fetch Command
You can retrieve, dearmor, and store the missing public key in a single chained terminal pipeline:
This command streams the key directly from the keyserver via HTTP and converts it into GPG binary format:
# Chained one-line key retrieval:
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x7FF49B32E90509E4" | \
sudo gpg --dearmor -o /etc/apt/keyrings/missing-repo.gpg
# Set read permissions:
sudo chmod 644 /etc/apt/keyrings/missing-repo.gpg
Step 3: Linking the Keyring in Your Repository Configuration
Once the key is stored in /etc/apt/keyrings/, instruct APT to use that specific key to verify the repository using the signed-by directive.
Open the corresponding repository file inside /etc/apt/sources.list.d/ in a text editor:
Add the [signed-by=/etc/apt/keyrings/filename.gpg] option before the repository URL:
# Example repository file: /etc/apt/sources.list.d/example.list
# Ensure the signed-by parameter is defined:
deb [signed-by=/etc/apt/keyrings/missing-repo.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu noble main
# Test package update to confirm resolution:
sudo apt update
# Output confirms:
# Hit:1 http://ppa.launchpad.net/ansible/ansible/ubuntu noble InRelease
# All packages are up to date. (Zero errors!)
Why apt-key is Deprecated: Security Implications
Running sudo apt-key adv --keyserver ... triggers a prominent warning: Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead.
Understanding why this legacy command was abolished is essential for modern system administrators:
| Attribute | Legacy apt-key Model | Modern signed-by Keyring Model |
|---|---|---|
| Key Storage Location | Global keyring in /etc/apt/trusted.gpg | Isolated keyrings in /etc/apt/keyrings/repo.gpg |
| Verification Scope | Global (Any imported key can sign any package) | Scoped strictly to the specific repository defined in sources.list |
| Supply Chain Risk | A compromised third-party PPA could sign updates for system packages (like curl or openssl) | Zero cross-signing risk; third-party keys are confined strictly to their own packages |
| Deprecation Status | Fully deprecated in Ubuntu 22.04 and 24.04 | Canonical and Debian recommended standard |
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
gpg: keyserver receive failed: Server indicated a failure / Connection timed out
Cause: Port 11371 (HKP) is blocked by your cloud provider or enterprise firewall.
Resolution: Query the keyserver over HTTPS (port 443) using hkps://keyserver.ubuntu.com:443 or curl.
gpg --keyserver hkps://keyserver.ubuntu.com:443 --recv-keys KEY_ID
W: An error occurred during the signature verification: EXPKEYSIG [KEY_ID]
Cause: The repository's GPG public key has expired past its validity date.
Resolution: Re-download the refreshed public key from upstream project maintainers or re-fetch from keyserver.
gpg --keyserver keyserver.ubuntu.com --recv-keys EXPIRED_KEY_ID
E: Conflicting distribution: ... InRelease is not signed with trusted keys
Cause: The keyring file specified in signed-by does not exist or has restrictive file permissions.
Resolution: Verify file existence and ensure permissions are set to 644: sudo chmod 644 /etc/apt/keyrings/*.gpg.
ls -la /etc/apt/keyrings/
Security Best Practices and Hardening
Never bypass GPG verification with --allow-unauthenticated in production; doing so opens your server to arbitrary remote code execution via spoofed packages.
Store third-party repository keys in /etc/apt/keyrings/ rather than /etc/apt/trusted.gpg.d/ to guarantee proper scoping.
Always set file permissions of GPG keyrings to 644 so the unprivileged _apt sandbox user can read the verification keys.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
apt update vs apt upgrade vs apt full-upgrade— Master the mechanics of package index updates and upgrades on Ubuntu.- How to Fix APT and dpkg Lock Errors on Ubuntu and Debian — Resolve package management process conflicts and lock file issues.
- Initial Server Setup on Ubuntu 24.04 LTS — Establish foundational server security and package repository baselines.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
apt-key binary may still exist for legacy compatibility, its usage outputs loud deprecation warnings and it will be completely removed in future releases. All modern scripts must use isolated keyrings in /etc/apt/keyrings/.-----BEGIN PGP PUBLIC KEY BLOCK-----). The --dearmor flag converts this base64 ASCII representation into compact binary OpenPGP packets required by APT.sources.list instead of using add-apt-repository, its public cryptographic signature key is not automatically downloaded, requiring a manual keyserver fetch.apt-key list and inspect individual modern keyrings using gpg --show-keys /etc/apt/keyrings/filename.gpg.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!