Executing routine package maintenance via sudo apt update on modern Ubuntu installations (such as Ubuntu 22.04 LTS, Ubuntu 24.04 LTS, and Debian derivatives) frequently generates a distinctive security warning: ‘Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.’ While packages still download and upgrade normally for the moment, this notification alerts system administrators that historical key management practices will eventually be blocked entirely.
The warning arises because the legacy apt-key utility placed repository authentication keys into a single, global keyring file. In that historical configuration, any single compromised third-party repository key could theoretically sign packages masquerading as official Ubuntu core packages. Modern Debian and Ubuntu architectures mandate isolated repository keys placed securely within the /etc/apt/keyrings/ directory. Here is how to modernise your repository signatures cleanly.
Identify the Deprecated Repository Keys
Before migrating legacy keys into dedicated security containers, you must identify the key fingerprint and associated third-party repository.
- Open your terminal and run the legacy listing command:
sudo apt-key list - Inspect the console output. Notice the warning banner reiterating deprecation, followed by listed blocks containing key signatures and software vendor names (e.g., Google Chrome, Spotify, Docker, or NodeSource).
- Locate the last eight characters of the 40-character hexadecimal fingerprint for the target key (for example:
D38B 4796).
Export the Key to the Dedicated Keyrings Directory
Ubuntu standards specify that third-party public GPG keys should reside in the dedicated /etc/apt/keyrings/ directory with world-readable (644) permissions.
- Ensure the system keyrings directory exists:
sudo mkdir -p -m 755 /etc/apt/keyrings - Export the specific key from your legacy global file into an individual
.gpgbinary file using its hexadecimal key identifier:sudo apt-key export D38B4796 | sudo gpg --dearmor -o /etc/apt/keyrings/example-vendor.gpg
(Replace D38B4796 with your actual key fingerprint, and example-vendor with an identifiable application name). - Verify that the resulting keyring file has proper file permissions so the unprivileged
_aptuser can read it:sudo chmod 644 /etc/apt/keyrings/example-vendor.gpg
Update the Repository Source Configuration File
With the dedicated key exported, you must update the repository configuration file located in /etc/apt/sources.list.d/ so that APT explicitly references the isolated keyring.
- Browse to your package source directory:
cd /etc/apt/sources.list.d/ - Open the corresponding
.listor.sourcesfile in a command-line editor:sudo nano example-vendor.list - Update the repository definition line to include the
signed-byattribute pointing directly to your exported keyring file:deb [arch=amd64 signed-by=/etc/apt/keyrings/example-vendor.gpg] https://repo.example.com/ stable main - Save your changes by pressing Ctrl + O, then press Enter and exit via Ctrl + X.
Remove the Stale Key from the Legacy Keyring
Once the isolated keyring is referenced by your repository sources, remove the old key from the deprecated global storage file to eliminate the warning message completely.
- Remove the legacy key using its identifier:
sudo apt-key del D38B4796 - Run a fresh package index update:
sudo apt update - The command should complete cleanly without triggering the legacy trusted.gpg warning banner.