Running apt update, adding third-party package repositories, or installing software from external software vendors on Ubuntu 22.04 LTS, Ubuntu 24.04 LTS, or Debian 12 Bookworm frequently outputs the notification: ‘W: Target Packages is configured multiple times… Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8))’. While package installations may still complete, the apt-key utility has been deprecated due to security vulnerabilities, and future distributions will completely block repository updates that rely on legacy shared keyrings. Migrating to modern detached cryptographic keyrings ensures package authenticity without compromising operating system security.
Why Is apt-key Deprecated in Modern Linux?
Historically, system administrators used apt-key add to import vendor public keys. However, this model introduces substantial security weaknesses:
- Global Trust Model Vulnerability: Keys added via
apt-key addare placed inside the central/etc/apt/trusted.gpgkeyring. A key trusted in this global ring can sign packages for any repository configured on your machine, allowing an untrusted third-party repository to overwrite core system packages. - Modern Signed-By Architecture: The Debian and Ubuntu package management specifications now mandate repository-specific keyrings stored in
/etc/apt/keyrings/and referenced explicitly via the[signed-by=...]parameter in repository source files. - ASCII Armoured Key Deprecation: Modern APT prefers de-armoured binary OpenPGP keys (
.gpg) or strictly parsed modern.asckeyrings rather than executing root-level shell imports through legacy scripts.
Step 1: Identify Keys Stored in the Legacy Keyring
Inspect the deprecated global keyring to find which third-party repository signatures must be migrated.
- Open your terminal and list all keys currently stored in the legacy database:
apt-key list - Review the output for keys marked under
/etc/apt/trusted.gpg. Each key entry contains an 8-character or 16-character hexadecimal fingerprint (e.g.pub rsa4096 2020-04-12 [SC] [expires: 2026-04-11] 4B0E D3B7 ...). - Note the last 8 characters of the key fingerprint for the repository you need to migrate (for example, Docker, Google Chrome, Spotify, or NodeSource).
Step 2: Export Legacy Keys into Dedicated Keyrings
Extract the vendor GPG key from the deprecated keyring and export it into the dedicated /etc/apt/keyrings/ directory.
- Ensure the recommended modern keyrings directory exists with secure permissions:
sudo install -m 0755 -d /etc/apt/keyrings - Export the specific key using its 8-character fingerprint (replace
XXXXXXXXwith your actual key fingerprint):sudo apt-key export XXXXXXXX | sudo gpg --dearmor -o /etc/apt/keyrings/vendor-archive-keyring.gpg - Set read-only permissions for non-root users so the APT sandbox user can read the signature:
sudo chmod a+r /etc/apt/keyrings/vendor-archive-keyring.gpg - Remove the key from the deprecated global keyring:
sudo apt-key del XXXXXXXX
Step 3: Update Repository Sources List with Signed-By Flag
Link the newly created detached keyring directly to the repository configuration file.
- Locate the repository file in
/etc/apt/sources.list.d/:grep -rnw '/etc/apt/sources.list.d/' -e 'vendor' - Open the corresponding
.listfile in your preferred text editor (e.g.sudo nano /etc/apt/sources.list.d/vendor.list). - Add the
[signed-by=/etc/apt/keyrings/vendor-archive-keyring.gpg]attribute immediately afterdeb:# Before: deb https://download.vendor.com/linux/ubuntu noble stable # After: deb [signed-by=/etc/apt/keyrings/vendor-archive-keyring.gpg] https://download.vendor.com/linux/ubuntu noble stable - Save the file and exit the editor (in nano, press
Ctrl + O,Enter, thenCtrl + X).
Step 4: Import Future Third-Party Keys the Modern Way
When adding new third-party software repositories in the future, avoid using apt-key add entirely. Use the secure modern download pattern:
- Download and de-armour the public key directly into
/etc/apt/keyrings/:curl -fsSL https://download.vendor.com/linux/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/vendor-archive-keyring.gpg sudo chmod a+r /etc/apt/keyrings/vendor-archive-keyring.gpg - Create the repository list file referencing the key:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/vendor-archive-keyring.gpg] https://download.vendor.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/vendor.list > /dev/null
Step 5: Refresh APT Package Indexes
Verify that package index synchronization proceeds cleanly without any deprecation warnings.
- Execute package index update:
sudo apt update - Confirm that the update completes with
All packages are up to datewithout displaying the apt-key is deprecated warning.
Migrating keys to isolated keyring files in /etc/apt/keyrings/ with explicit signed-by flags ensures secure and future-proof package management in Debian and Ubuntu.