Running repository updates or adding external software archives on Ubuntu 22.04 LTS, 24.04 LTS, or newer releases frequently produces an annoying terminal warning: “W: http://…: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details”. While packages continue to install, this persistent warning clutters terminal logs and signals that future APT versions will reject these repository signing keys outright.
The deprecation of apt-key is a crucial security enhancement in the Debian and Ubuntu ecosystems. Historically, adding a third-party signing key via apt-key add placed the cryptographic certificate inside a single global keyring (/etc/apt/trusted.gpg). This gave that third-party key blanket authority to sign and validate packages for every repository on your system, creating a significant security vulnerability. The modern APT architecture isolates each external key inside /etc/apt/keyrings/ and links it strictly to its respective repository. This guide walks you through migrating your legacy keys cleanly.
Method 1: Identify Legacy Keys in /etc/apt/trusted.gpg
Before migrating keys, list all signing certificates currently residing inside the obsolete global keyring to discover their key IDs.
- Open your terminal by pressing Ctrl + Alt + T.
- List all legacy keys by executing:
apt-key list - Review the output. Notice the warning banner confirming that
apt-keyis deprecated. - Look for third-party repository entries (such as Google Chrome, Spotify, NodeSource, or Docker).
- Locate the 8-character or 16-character string at the end of the
publine (the Key ID) or the last 8 characters of the 40-character fingerprint. For example:
In this example, the key identifier ispub rsa4096 2016-04-12 [SC] EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F634 3A38 863D uid [ unknown] Google Inc. (Linux Packages Signing Authority)3A38863D.
Method 2: Export Legacy Keys into /etc/apt/keyrings/
The modern standard stores dedicated, de-armoured GPG keyrings inside the restricted directory /etc/apt/keyrings/.
- Ensure the dedicated keyrings directory exists with secure permissions:
sudo install -m 0755 -d /etc/apt/keyrings - Export the specific key from the legacy keyring into a standalone
.gpgbinary file. Replace<KEY_ID>with the last 8 characters of the fingerprint and choose an appropriate filename:sudo apt-key export 3A38863D | sudo gpg --dearmor -o /etc/apt/keyrings/google-chrome.gpg - Set standard read permissions so the APT unprivileged user can read the key:
sudo chmod a+r /etc/apt/keyrings/google-chrome.gpg - Repeat this export command for any other third-party keys listed in
apt-key list.
Method 3: Update Repository Sources with the signed-by Option
Once the key is securely saved in /etc/apt/keyrings/, update the repository source line in /etc/apt/sources.list or /etc/apt/sources.list.d/ to reference this isolated key.
- Locate the repository file inside
/etc/apt/sources.list.d/:ls /etc/apt/sources.list.d/ - Open the relevant repository configuration file in nano:
sudo nano /etc/apt/sources.list.d/google-chrome.list - Add the
[signed-by=/etc/apt/keyrings/filename.gpg]attribute immediately after thedebkeyword. For example:deb [arch=amd64 signed-by=/etc/apt/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main - Save the file by pressing Ctrl + O followed by Enter, then exit by pressing Ctrl + X.
Method 4: Remove the Legacy Key and Validate apt update
To eliminate the deprecation warning permanently, purge the migrated key from the obsolete global keyring.
- Delete the key from the legacy
trusted.gpgfile:sudo apt-key del 3A38863D - If all third-party keys have been migrated, you can safely remove or rename the obsolete keyring:
sudo mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg.backup - Run a fresh repository update:
sudo apt update - Verify that the update completes cleanly without displaying any “Key is stored in legacy trusted.gpg” deprecation warnings.
Modern APT Keyring Management Reference Table
The table below provides a quick reference for migrating repository key formats in Ubuntu:
| Architecture Component | Legacy Approach (Deprecated) | Modern Standard (Ubuntu 22.04+) |
|---|---|---|
| Key Storage Location | /etc/apt/trusted.gpg (Single monolithic file) | /etc/apt/keyrings/<vendor>.gpg (Isolated files) |
| Key Import Tool | apt-key add <keyfile> | curl -fsSL <url> | sudo gpg –dearmor -o /etc/apt/keyrings/<name>.gpg |
| Repository Syntax | deb https://repo.example.com/ stable main | deb [signed-by=/etc/apt/keyrings/<name>.gpg] https://repo… |
| Security Scope | Global trust: key validates all repos | Scoped trust: key validates only specified repo |
| Keyring Directory Permissions | Root owned default | 0755 directory; 0644 (a+r) keyring files |
Adding Future Repositories Without Triggering apt-key Warnings
When installing new software vendors in the future, avoid running legacy commands like curl ... | sudo apt-key add - found in outdated web tutorials. Instead, utilize the secure single-line standard: curl -fsSL https://vendor.com/key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/vendor.gpg, followed by referencing the key in your sources line with [signed-by=/etc/apt/keyrings/vendor.gpg].