Fix Missing GPG Key Apt Repository Errors (NO_PUBKEY)

You might see a missing public GPG key error (“NO_PUBKEY”) on Debian, Ubuntu or Linux Mint when running apt update / apt-get update. This can happen when you add a repository, and you forget to add its public key, or maybe there was a temporary key server error when trying to import the GPG key.

Source: Fix Missing GPG Key Apt Repository Errors (NO_PUBKEY) – Linux Uprising Blog

Quick’n’dirty solution:

sudo apt-key adv --keyserver --recv-keys THE_MISSING_KEY_HERE

apt update 2>&1 1>/dev/null | sed -ne 's/.<em>NO_PUBKEY //p' |
while read key; do if ! [[ ${keys[</em>]} =~ "$key" ]]; then sudo apt-key
adv --keyserver --recv-keys "$key"; keys+=("$key");
fi; done

Yes, I know apt-key is being deprecated…

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.