How to Fix ‘W: Key is Stored in Legacy Trusted.gpg Keyring’ in Ubuntu

When executing sudo apt update on modern versions of Ubuntu (such as Ubuntu 22.04 LTS Jammy Jellyfish or Ubuntu 24.04 LTS Noble Numbat), many system administrators and desktop users encounter a prominent security warning: “W: http://… InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.”

While this notice is classified as a warning rather than a fatal error, it indicates that third-party package signing keys are stored in a deprecated global keyring. Under the modern Debian and Ubuntu security architecture, third-party GPG keys must be isolated to individual keyrings located in /etc/apt/keyrings and explicitly bound to specific repository source files. This guide demonstrates how to export legacy keys to dedicated keyrings and silence the warning.

Understanding Why apt-key Is Deprecated

Historically, administrators added repository signing keys globally using apt-key add. This stored all keys in a single file: /etc/apt/trusted.gpg. The severe security flaw with this approach is that any key stored in the global keyring is trusted to sign packages for all configured repositories. If a third-party PPA or vendor repository became compromised, its key could theoretically sign malicious updates for core system packages.

The modern standard stores individual keys under /etc/apt/keyrings/ with restricted read permissions (644) and links each key directly to its corresponding repository definition using the signed-by attribute.

Identify the Deprecated Key Fingerprint

Before migrating a legacy key, query your existing trusted keyring to find the specific key fingerprint that triggered the warning:

apt-key list

In the terminal output, locate the repository that printed the warning during apt update (such as Google Chrome, Spotify, or Docker). Note the last 8 characters of the pub key line (the key ID) or the full 40-character fingerprint.

Export the Key to /etc/apt/keyrings

Once you have identified the key, export it directly into the modern keyrings directory:

  1. Ensure the modern keyrings directory exists:
    sudo mkdir -p -m 755 /etc/apt/keyrings
  2. Export the key from the legacy keyring into a dedicated binary keyring file (replace KEY_ID with your specific 8-character ID, and name the output file appropriately):
    sudo apt-key export KEY_ID | sudo gpg --dearmor -o /etc/apt/keyrings/repository-name.gpg
  3. Set appropriate world-readable permissions so the _apt system user can read the signature:
    sudo chmod 644 /etc/apt/keyrings/repository-name.gpg

Update the Repository Source Configuration

Next, update the repository source file so APT knows which dedicated keyring verifies the packages:

  1. Locate the repository file in /etc/apt/sources.list.d/:
    ls /etc/apt/sources.list.d/
  2. Edit the file using nano:
    sudo nano /etc/apt/sources.list.d/repository-name.list
  3. Modify the line to include the [signed-by=/etc/apt/keyrings/repository-name.gpg] directive immediately after the initial deb declaration. For example:
    deb [arch=amd64 signed-by=/etc/apt/keyrings/repository-name.gpg] http://repo.example.com/ stable main
  4. Save the file by pressing Ctrl + O and exit with Ctrl + X.

Delete the Key from the Legacy Keyring

Finally, remove the legacy key from /etc/apt/trusted.gpg so the deprecation warning will no longer trigger:

sudo apt-key del KEY_ID

Run your update command to confirm that the package cache updates cleanly without any deprecation messages:

sudo apt update

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.