When managing software repositories on Ubuntu and other Debian-based systems, maintaining a secure and verified package source is essential. The command apt-key plays a critical role in this process by managing the authentication keys used to verify the integrity and origin of packages. Understanding how to correctly list these keys is a fundamental skill for any system administrator aiming to maintain a secure and stable environment.
Understanding APT Keys and Their Role
The Advanced Package Tool (APT) relies on a system of cryptographic keys to authenticate software packages. When you add a repository to your system's sources list, that repository provides a GPG key. This key is used to sign the package lists and files it generates. By verifying the signature using the correct public key, apt ensures that the packages you download have not been tampered with and are genuinely from the declared source. Listing these keys allows you to audit and manage the trust you have placed in various external sources.
The Core Command: apt-key list
The primary command for displaying the keys stored in your system's trusted keyring is apt-key list. This command requires superuser privileges to access the keyring files, so it is typically executed with sudo. Running this command without any arguments will output a list of all trusted keys, showing their long numerical identifiers, the user ID associated with them, and the public key material itself. This provides a complete overview of the sources your system currently trusts.

Executing the Command
To view the list of trusted keys, open your terminal and enter the following command:
sudo apt-key list
The output is organized into sections for each key, clearly indicating the key ID and the repository it corresponds to. This straightforward output is invaluable for quickly checking which repositories are currently active and trusted on your system.
Interpreting the Output
Understanding the output of apt-key list is crucial for effective system management. Each section represents a distinct key. The lines beginning with pub indicate the public key itself, displaying details such as the key size, type, and creation date. The uid lines show the user ID, which typically contains the name of the repository and its associated project. Familiarizing yourself with this format allows you to confirm that a repository's key is correctly installed and has not expired.

Piping to GPG for Advanced Details
For a more detailed and specific view of a key, you can combine apt-key with the core GPG tools. By piping the output of apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY_ID>, you can fetch the key from a public keyserver and then use --fingerprint to display its full fingerprint. This is particularly useful when you need to verify the exact key against a fingerprint published on the repository's official website, adding an extra layer of security verification.
Managing Keys and Best Practices
While apt-key add was the standard for adding new keys, the modern approach favors placing key files directly into the /usr/share/keyrings/ directory. This method, which uses the syntax <keyfile> gpgv -q | gpg --no-dearmor > /usr/share/keyrings/archive-keyring.gpg, is more secure and modular. Consequently, the apt-key list command will still display these keys, but they are managed outside of the legacy keyrings. This shift represents the industry's move toward a more robust and maintainable key management strategy.
Troubleshooting and Verification
If you encounter 'NO_PUBKEY' errors when running apt update, it means your system is missing the key needed to verify a specific repository. The error message will usually include the short key ID. You can then use apt-key adv --keyserver keyserver.ubuntu.com --recv-keys NO_PUBKEY_ID to fetch and add the correct key. Regularly using apt-key list is a best practice that helps you verify that only intended and necessary repositories are trusted, ensuring the integrity of your package management system.






















