Website Vidya
Linux & ServersStep-by-Step Guide

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.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Fix the NO_PUBKEY GPG Error on apt update in Ubuntu
AI Executive SummaryWebsiteVidya AI

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.

Key Highlights
  • Prerequisites and Supported Releases
  • Understanding the NO_PUBKEY Error Anatomy
  • Method 1: Fetching Missing Keys Directly from Ubuntu Keyserver (Modern Standard)
Grounded in full engineering runbookWebsiteVidya AI Engine

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.

Advertisement

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.

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:

Advertisement
  • A server or computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • An unprivileged user account with sudo administrative 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.

Advertisement

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:

AttributeLegacy apt-key ModelModern signed-by Keyring Model
Key Storage LocationGlobal keyring in /etc/apt/trusted.gpgIsolated keyrings in /etc/apt/keyrings/repo.gpg
Verification ScopeGlobal (Any imported key can sign any package)Scoped strictly to the specific repository defined in sources.list
Supply Chain RiskA 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 StatusFully deprecated in Ubuntu 22.04 and 24.04Canonical 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.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
While the 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/.
GPG keys are often distributed as ASCII-armored text blocks (beginning with -----BEGIN PGP PUBLIC KEY BLOCK-----). The --dearmor flag converts this base64 ASCII representation into compact binary OpenPGP packets required by APT.
When a Personal Package Archive (PPA) is added manually to sources.list instead of using add-apt-repository, its public cryptographic signature key is not automatically downloaded, requiring a manual keyserver fetch.
You can inspect legacy global keys with apt-key list and inspect individual modern keyrings using gpg --show-keys /etc/apt/keyrings/filename.gpg.
RR
Written byVerified Author

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.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout