How to Delete GPG Keys on Linux

GPG Key or GNU Privacy Guard key is a cryptography implementation. Linux users use GPG Keys to secure the information transfer between users and verify the originality of the message. Learn to delete the GPG keys on Linux hassle-free if the keyring is overloaded.  

In this article, you will learn how to delete GPG Keys on Linux not only for a single user but also for multiple users. Before deleting the keys, make sure to understand the types of GPG keys discussed in the next section. For more information, you can also check out official documentation.

Types of GPG Keys

The GPG key consists of two keys: Private and Public. Linux uses a Public key for data encryption and a Private key for decryption. Furthermore, Linux users can only share the Public key with the others. On the other hand, the Private key is kept secret as other users can use this key to decrypt the secret information. 


For this tutorial, you will need a system with sudo privileges or a root user login. Furthermore, you will also need an already existing set of GPG Keys for at least a single user. 

Delete GPG Keys on Linux

Now that you know what GPG Keys are all about, it is time to learn how to delete GPG Keys. There are two ways to delete any key: use the UserID to delete the key or use the KeyID. Also, you must delete the Private key first and then delete the Public key to ensure the successful deletion of the keys. 

We have sectioned this tutorial into various parts to ensure that you can follow the article easily. So, let’s get started.

List GPG Keys on Linux

Before deleting the GPG Keys on Linux, you must check your GPG Key. For this step, open the terminal using the “Ctrl+Alt+T” shortcut keys, then type the gpg command. Make sure to identify which key you want to view. To view Public keys, add the –list-keys option after the gpg command. 

Alternatively, you can type –list-secret-keys to view the Private key. Hit “Enter key” to view the output. For example:

gpg --list-keys

The output would look something like this:

Delete GPG keys on Linux

For multiple users, this is what the output would look like:

Delete GPG keys on Linux

However, if there is no GPG Key on Linux, you will not get any output. For the sake of this tutorial, I have created a set of GPG Keys on my system. 

For the Private keyring list, execute the command given below:

gpg --list-secret-keys

You should get similar output like this one:

Delete GPG Keys on Linux

Delete GPG Keys of a Single User

Let’s look at how to delete GPG Keys of a single user. We will delete both the Private and Public GPG Keys using UserID and KeyID both.

Delete GPG Key Using UserID

To delete the Private Key of a single user using the UserID, execute the command given below:

gpg --delete-secret-key [uid]

For instance, if the username is “sidrah”, this is what the command should look like:

gpg --delete-secret-key sidrah

It will confirm twice before deleting the Private key as shown below:

Delete Single User GPG Key Using UID

Type “Y” twice. After that, a confirmation message will appear:

Delete Single User GPG Key Using UID

Click the “Delete Key” button. Success!

The process for deleting the Public key using the UserID is similar. Here is the syntax: 

gpg --delete-key [uid]

For example: 

gpg --delete-key sidrah

Hit “Y” to continue with the deletion process. 

Single User UID

You have successfully deleted the Private and Public GPG keys using the UserID. To verify the successful deletion, run the following commands:

gpg --list-keys

For Private key listing:

gpg --list-secret-keys

Delete GPG Key Using KeyID

The second way to delete these keys is to use the KeyID instead of the UserID. For this step, follow the same process as you did with UserID. However, do not forget to replace the UserID with KeyID. The commands look something like this: 

gpg --delete-secret-key [Key_ID]

When deleting a Private key, the system will confirm twice. Type “Y” and hit the Enter key. A confirmation pop-up will appear, as shown in the previous step. Make sure to click the “Delete Key” button.

gpg --delete-key [Key_ID]

Hit “y” to continue with the deletion. 

The error-free output would indicate the successful deletion of GPG keys using KeyID. Verify it using the commands given below: 

gpg --list-keys
gpg –list-secret-keys


Single User

Now, you can see that there is no entry for user “sidrah”.

Delete GPG keys of Multiple Users 

Let’s look at how to delete GPG Keys of multiple users simultaneously. We’re going to remove the Private and Public GPG Keys using UserID and KeyID both.

Delete GPG Key Using UserID

Similar to single-user key deletion, you can use the gpg command for multiple user GPG keys deletion. First, list the Private key to select the users: 

gpg --list-secret-keys

Then, delete the secret key using the gpg command. The syntax is:

gpg --delete-secret-key [uid1] [uid2]

Make sure to replace the UserIDs with the names of the required users. The keys will be deleted in the order the UserIDs appear. For instance, to delete the Private key for users “Thomas” and “Charlotte”, the command would look like this:

gpg –delete-secret-key Thomas Charlotte

For both users, the system will ask for deletion confirmation separately. Specifically:

Multiple Users Using UserID

After that, delete the Public key of the same users: 

gpg --delete-key  [uid1] [uid2]

For example:

gpg --delete-key  Thomas Charlotte

Hit “Y” to continue with the successful deletion process. 

Make sure to verify the successful deletion using the following commands for Private and Public Keys, respectively:

gpg --list-keys
gpg –list-secret-keys

If you do not see the username in the list, the keys have been deleted successfully. 

Delete GPG Key Using KeyID

Similarly, you can delete the keys using the KeyID of multiple users. The syntax would look something like this: 

gpg --delete-secret-key [Key_ID1] [Key_ID2]
gpg --delete-key [Key_ID1] [Key_ID2]

Hit “y” to continue with the deletion. 

Remember to replace the KeyIDs with the official IDs present in the GPG list. To ensure that you have used the correct KeyID, execute the following commands before deleting the keys:

gpg --list-keys
gpg –list-secret-keys

After the deletion process is complete, run the same commands given above to verify the successful deletion. 

Empty List

Since I have deleted all the Private and Public GPG Keys from my system, there exists no entry for the gpg --list-keys and gpg –list-secret-keys command. 

And that is how you can delete GPG Keys on Linux. The process is pretty simple. Also, as a Linux user, it is essential to delete the users to avoid having a long list of names in your GPG Keyring. This article covered how to delete GPG keys of single and multiple users on Linux using both the UserID and KeyID. We hope you found this article to be helpful. 

If this guide helped you, please share it.

Leave a Reply
Related Posts