apt-get – NO_PUBKEY – how to add the pubkey

apt-get – NO_PUBKEY  – how to add the pubkey

I have run into this situation many times on Ubuntu and Debian  so I thought I would finally document the fix.

When run into a apt-get error where there NO_PUBKEY avaiable for a package you want to install you get this error

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY xxxxxxxxxxxxxxxxxxxxxx

This means your system does not trust the signature,  so if you trust mit’s keyserver,  you can do this to fix it

root@servername:~# gpg --keyserver pgp.mit.edu --recv-keys xxxxxxxxxxxxxxxxxxxxxx
root@servername:~# gpg --armor --export xxxxxxxxxxxxxxxxxxxxxx| apt-key add -

Solves it for me every time so far,  at some point though I might run into a situation where mit does not have the keys,  for now though this works,  and I trust them

Entire script below

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY xxxxxxxxxxxxxxxxxxxxxx
 root@servername:~# gpg --keyserver pgp.mit.edu --recv-keys xxxxxxxxxxxxxxxxxxxxxx
 root@servername:~# gpg --armor --export xxxxxxxxxxxxxxxxxxxxxx| apt-key add -
 OK