The apt-key
command is used in Debian-based Linux systems to manage package keys. These keys are used to verify the authenticity of packages before they are installed on the system. The apt-key
command can be used to add, delete, and list keys used by the Advanced Package Tool (APT) package manager.
Overview
Adding Keys
To add a new key, use the add
option followed by the URL or file path of the key. For example:
sudo apt-key add /path/to/keyfile.asc
or
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 12345678
The first command adds a key from a local file, while the second command retrieves a key from a keyserver.
Deleting Keys
To delete a key, use the del
option followed by the key ID or fingerprint. For example:
sudo apt-key del 12345678
or
sudo apt-key del "Key Fingerprint"
Listing Keys
To list all keys currently used by APT, use the list
option:
sudo apt-key list
This will display a list of all keys with their associated fingerprints.
Exporting Keys
To export a key, use the export
option followed by the key ID or fingerprint. For example:
sudo apt-key export 12345678 > keyfile.asc
This will export the key to a file called keyfile.asc
.
Importing Keys
To import a key from a file, use the add
option followed by the file path. For example:
sudo apt-key add /path/to/keyfile.asc
Options
The apt-key
command has several options that can be used:
Option | Description |
---|---|
add | Add a new key to the keyring |
del | Delete a key from the keyring |
export | Export a key to a file |
adv | Pass advanced options to gpg |
list | List all keys in the keyring |
finger | Display the fingerprint of a key |
recv | Download a key from a keyserver |
update | Download the latest list of keys from the keyserver |
Troubleshooting Tips
- If you get an error message saying “gpg: no valid OpenPGP data found”, make sure that the file you are trying to import is a valid key file.
- If you get an error message saying “gpg: keyserver receive failed: No keyserver available”, try using a different keyserver or check your internet connection.
- If you get an error message saying “gpg: keyserver timed out”, try using a different keyserver or check your internet connection.
Notes
- The
apt-key
command requires administrative privileges, so make sure to run it withsudo
. - The
apt-key
command usesgpg
(GNU Privacy Guard) to manage keys, so make sure thatgpg
is installed on your system before usingapt-key
.