Ubuntu 18.04 apt-get update出现NO_PUBKEY错误的解决方法

最近在VPS中使用apt-get update命令时,出现了如下的错误,形式如“W: GPG error: http://security.ubuntu.com trusty-security Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY XXXXX”

该问题也会出现在Ubuntu其他的版本中,实际上在商家上线的系统模版中或多或少都有一些类似的细节错误,值得我们在使用中注意并修正。当然这一类的问题实际上并不算大,只是解决起来可能需要一些搜索工作。

apt-get update返回NO_PUBKEY错误的解决方法

报错代码如下:

Err:5 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3F01618A51312F3F
Fetched 23.3 kB in 9s (2,673 B/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3F01618A51312F3F
W: Failed to fetch https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/dists/bionic/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3F01618A51312F3F
W: Some index files failed to download. They have been ignored, or old ones used instead.

解决办法:

将公钥添加至服务器,运行如下命令解决:

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32

添加成功后终端输出为:

Executing: /tmp/apt-key-gpghome.4JQ9tOjCB7/gpg.1.sh --recv-keys --keyserver keyserver.ubuntu.com 3F01618A51312F3F
gpg: key 3F01618A51312F3F: public key "GitLab B.V. (package repository signing key) <packages@gitlab.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

这样再去sudo apt-get update就不会有问题了。

参考文献:https://www.jb51.net/os/Ubuntu/169716.html