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 - https://packages.grafana.com/gpg.key | sudo apt-key add -
$ sudo add-apt-repository "deb https://packages.grafana.com/oss/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
/etc/apt/trusted.gpg
--------------------
pub   rsa2048 2017-01-24 [SC]
      4E40 DDF6 D76E 284A 4A67  80E4 8C8C 34C5 2409 8CB6
uid           [ unknown] Grafana <info@grafana.com>
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
OK

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 https://packages.grafana.com/enterprise/deb stable main

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

Questions? Email root@linuxdev.net

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 http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - Thanks...
How to remove a apt-key which I have added?
I added a key like this: wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -sudo sh -c ’echo deb http://pkg.jenkins-ci.org/debian binary/ &gt; /etc/apt/sources.list.d/

Subscribe to Linux Developer

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe