NO_PUBKEY
在虚拟机体验了几天Ubuntu感觉还不错,今天直接在笔记本上安装上了。由于Ubuntu官方的软件源着实是太慢了,所以我第一件事情就是将软件源换成国内的镜像源(具体操作可以参考文章:Linux实战002:下载软件太慢了?赶紧更换国内镜像源吧!)。但是在更新软件源的时候遇到一个少见的错误,系统提示我找不到公钥导致The repository “***” is not signed(由于没有公钥,GPG无法验证签名)。这就导致我的系统无法使用apt下载安装软件了,瞬间给我整懵圈了....
# sudo apt-get update
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
GPG error: http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
The repository 'http://mirrors.aliyun.com/ubuntu bionic-security InRelease' is not signed.
Updating from such a repository can't be done securely, and is therefore disabled by default.
See apt-secure(8) manpage for repository creation and user configuration details.
安装公钥
这时候我们就需要先来导入公钥,我们可以利用终端来实现。前面我们在更新的时候系统提示我们缺少公钥:NO_PUBKEY 3B4FE6ACC0B21F32,NO_PUBKEY后面的字符就是需要导入的Key值,我们执行以下2个命令就可以把公钥导入系统了, 注意命令最后面还有一个“-”。
# gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
# gpg --export --armor 3B4FE6ACC0B21F32 | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
总结:
除了gpg我也可以使用apt-key来导入公钥,方法也非常简单只要执行以下命令即可。当然别忘了更换keys后面的秘钥ID,如果需要多个公钥时可以直接在后面追加(空格区分)。
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32