apt-get update出现NO_PUBKEY提示的解决方法

问题现象

在执行apt-get update时,出现如下提示:

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

解决办法

一般来讲,可以直接从key server获取缺失的公钥,Debian系统命令如下:

1
sudo apt-key adv --keyserver keyring.debian.org --recv-keys B5B7720097BB3B58

Ubuntu系统命令如下:

1
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B5B7720097BB3B58

不同系统的区别就是换了个key server,除上述keyserver外,其它可用的key server还有

1
2
keys.gnupg.net
pool.sks-keyservers.net

这些server同时还提供了Web页来搜索key的功能,https://sks-keyservers.net/overview-of-pools.php给出了一个server pool列表。

此外,有些较旧的系统,可能用上述命令也获取不到缺失的公钥,此时,可以使用下面描述的方法,这种方法事实上一次安装了许多的公钥。用下列命令找出相应系统的keyring包,然后安装:

1
2
3
4
5
6
7
8
$ apt-cache search keyring | grep "debian" 
debian-archive-keyring - GnuPG archive keys of the Debian archive
debian-edu-archive-keyring - GnuPG archive keys of the Debian Edu archive
debian-keyring - GnuPG keys of Debian Developers and Maintainers
debian-ports-archive-keyring - GnuPG archive keys of the debian-ports archive
emdebian-archive-keyring - GnuPG archive keys for the emdebian repository
neurodebian-archive-keyring - neuroscience-oriented distribution - GnuPG archive keys
$ sudo apt-get install debian-archive-keyring debian-keyring debian-ports-archive-keyring

一般安装上面3个包即可解决,如果不行,可以再把其它几个也装上。Ubuntu系统的话,尝试以下命令:

1
2
3
4
5
6
7
$ apt-cache search keyring | grep "ubuntu"
ubuntu-cloudimage-keyring - GnuPG keys of the Ubuntu Cloud Image builder
ubuntu-extras-keyring - GnuPG keys of the Ubuntu extras archive
ubuntu-keyring - GnuPG keys of the Ubuntu archive
ubuntu-cloud-keyring - GnuPG keys of the Ubuntu Cloud Archive
ubuntukylin-keyring - GnuPG keys of the Ubuntu Kylin archive
$ sudo apt-get install ubuntu-keyring ubuntu-extras-keyring

同样地,如果安装的这2个包不行,就把其它的也装上。