Howto: Delete APT Key and Repository Using apt-key on Debian Linux

Howto: Delete APT Key and Repository Using apt-key on Debian Linux

Let's suppose you have added a key using apt-key. For example, you might have been installing Grafana and ran the following commands.

$ sudo apt-get install -y apt-transport-https
$ sudo apt-get install -y software-properties-common wget
$ wget -q -O - | sudo apt-key add -
$ sudo add-apt-repository "deb stable main"
$ sudo apt-get update
$ sudo apt-get install grafana

We can now see the keys we added by listing the keys using the apt-key list command.

$ apt-key list
pub   rsa2048 2017-01-24 [SC]
      4E40 DDF6 D76E 284A 4A67  80E4 8C8C 34C5 2409 8CB6
uid           [ unknown] Grafana <>
sub   rsa2048 2017-01-24 [E]

Now we want to delete the key from our trusted list. We can delete the key by using the key ID found in the above output and the apt-key del command. Note that the key ID is 10 bytes - so only take the first half of the second line of pub.

$ apt-key del 4E40 DDF6 D76E 284A 4A67

The key is now deleted. We can verify by listing our keys again.

$ apt-key list

If we want, we can also check the repository which was added.

$ cat /etc/apt/sources.list
deb stable main

To delete the repository, open the file in a text editor and delete the relevant line.

Questions? Email

Relevant Links

How can I remove gpg key that I added using apt-key add -?
I don’t need the key in my server’s keyring anymore. Is it possible to remove it? I added the key using this command: curl | apt-key add - Thanks...
How to remove a apt-key which I have added?
I added a key like this: wget -q -O - | sudo apt-key add -sudo sh -c ’echo deb binary/ &gt; /etc/apt/sources.list.d/