Automatically import missing GPG Keys with launchpad-getkeys

I recently stumbled upon this problem of gpg key migration while working with ROS packages.

As a part of the measures to deal with a recent security incident with build.ros.org (Security issue on ROS build farm), the old keys are changed. For ROS2 as well regarding same reason.

From above looks like i am going to be in this same trouble again and again as they will do this key rotation for security at some interval.

To manually do all the steps given is too troublesome for me. So voilà here is my solution.

“Launchpad-getkeys” is a script that imports these missing keys automatically. Follow below steps to get free from this hassle.

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install launchpad-getkeys

After installing, to import just run:

sudo launchpad-getkeys

So now all in need to do is call above script and it will do all heavy liftling.

I also have another fun method if you are interested by means of alias in your .bashrc or .zshrc file. Add following line in your respective shell config file and you are good to go. No need for installing anything but this does not work for proxy servers.

alias autokey='sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key | sudo apt-key add -; done'

If you want to execute directly from root like me then use below:

alias autokey='apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key | apt-key add -; done'

Now just run:

autokey

Happy key migration for ya !!

More info here.

Join the Discussion

Blog at WordPress.com.

Up ↑