How to fix apt-get update “The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY” error

If a warning like in the title appears while updating apt, you can recheck public keys and renew them if necessary with the code below;

sudo apt-get update 2>&1 |
sed -ne 's?^.*NO_PUBKEY ??p' |
xargs -r -- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys