Software & AppsOperating SystemLinux

How To Remove GPG Key Added with apt-key add – Command?

Ubuntu 14

In the world of Linux, the apt-key command is a powerful tool used to manage the list of keys used by apt to authenticate packages. These keys are essential in ensuring the packages you install are genuine and haven’t been tampered with. However, there may be times when you need to remove a key from your system. In this article, we will walk you through the process of removing a GPG key that was added using the apt-key add command.

Quick Answer

To remove a GPG key that was added with the apt-key add command, you can use the apt-key del command followed by the key ID or fingerprint. For example, sudo apt-key del EFE21092 or sudo apt-key del "8439 38DF 228D 22F7 B374 2BC0 D94A A3F0 EFE2 1092". Don’t forget to run sudo apt update after removing the key.

Understanding the apt-key Command

The apt-key command is part of the Advanced Packaging Tool (APT), which is a package management system used by Debian and its derivatives like Ubuntu. The apt-key command specifically manages the list of keys used by APT for authenticating packages.

When you add a key using apt-key add, it’s added to the APT’s keyring. If you want to remove a key from the keyring, you can do so using apt-key del.

Listing All Keys

Before you can remove a key, you need to know its ID or fingerprint. To list all the keys in your keyring, use the following command:

sudo apt-key list

This command will display a list of all the keys in your keyring, along with their IDs and fingerprints.

Removing a Key Using the Key ID

Once you have identified the key you want to remove, note its key ID, which is the last 8 characters of the long hex string. You can remove the key using the following command:

sudo apt-key del <keyid>

Replace <keyid> with the actual key ID of the key you want to remove. For example:

sudo apt-key del EFE21092

After removing the key, run sudo apt update to update the package lists.

Removing a Key Using the Key Fingerprint

If you prefer, you can also remove a key using its fingerprint, which is the long hex string. Use the following command:

sudo apt-key del "<fingerprint>"

Replace <fingerprint> with the actual fingerprint of the key you want to remove. For example:

sudo apt-key del "8439 38DF 228D 22F7 B374 2BC0 D94A A3F0 EFE2 1092"

Don’t forget to run sudo apt update after removing the key.

Removing a Key Using a GUI (For Ubuntu Users)

If you’re using Ubuntu, you can also remove a key using the GUI. Here’s how:

  1. Open the “Software & Updates” application.
  2. Go to the “Authentication” tab.
  3. Find the key you want to remove and uncheck the corresponding checkbox.
  4. Click “Close” and enter your password if prompted.
  5. Run sudo apt update to update the package lists.

Conclusion

That’s it! You now know how to remove a GPG key that was added using the apt-key add command. Remember to always run these commands with administrative privileges using sudo, and to update the package lists after removing a key.

Whether you’re a system administrator or just a Linux enthusiast, understanding how to manage your APT keys is a valuable skill. Keep exploring and learning!

How do I know which key I want to remove?

To identify the key you want to remove, you can list all the keys in your keyring by using the sudo apt-key list command. The command will display a list of all keys along with their IDs and fingerprints.

Can I remove a key using its fingerprint instead of the key ID?

Yes, you can remove a key using its fingerprint. Use the command sudo apt-key del "<fingerprint>" and replace <fingerprint> with the actual fingerprint of the key you want to remove. Remember to enclose the fingerprint in double quotes.

Do I need to update the package lists after removing a key?

Yes, after removing a key using apt-key del, it is recommended to run sudo apt update to update the package lists. This ensures that your system has the latest information about available packages.

Can I remove a key using a GUI on Ubuntu?

Yes, if you’re using Ubuntu, you can remove a key using the "Software & Updates" application. Open the application, go to the "Authentication" tab, find the key you want to remove, uncheck the corresponding checkbox, click "Close," and enter your password if prompted. Afterward, run sudo apt update to update the package lists.

Leave a Comment

Your email address will not be published. Required fields are marked *