GitLab GPG key 更新

心得

今天打算要來更新 GitLab 的時候發現系統吐出以下錯誤:

[email protected]:~$ apt update
[sudo] password for clarence:
Hit:1 http://tw.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://tw.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://tw.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://tw.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:6 http://tw.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [914 kB]
Get:5 https://packages.gitlab.com/gitlab/gitlab-ee/ubuntu bionic InRelease [23.3 kB]
Err:5 https://packages.gitlab.com/gitlab/gitlab-ee/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3F01618A51312F3F
Fetched 1,190 kB in 3s (394 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
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-ee/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-ee/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.

看到以上錯誤就知道是 GPG Key 的問題了,所以今天就要來說明怎麼更新 GPG Key

尋找 GitLab GPG key file

其實要更新很簡單主要就是要先找到 GPG Key 在哪裏,我們先到 GitLab 的 packages,找到 GPG Key 的文件,可以在第二行找到 gitlab/gitlab-ce has its APT metadata signed with the default GPG key. 點開就可以找到我們要的 Key file 了,那怎麼更新 GPG Key 到我的系統呢?只要一行指令

apt key 加入

curl --silent https://packages.gitlab.com/gpg.key | sudo apt-key add -

那我們再測試一次 apt update

[email protected]:~$ apt update
Hit:1 http://tw.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://tw.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://tw.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:4 http://tw.archive.ubuntu.com/ubuntu bionic-security InRelease
Get:5 https://packages.gitlab.com/gitlab/gitlab-ee/ubuntu bionic InRelease [23.3 kB]
Get:6 https://packages.gitlab.com/gitlab/gitlab-ee/ubuntu bionic/main amd64 Packages [34.7 kB]
Fetched 58.1 kB in 4s (15.4 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.

可以正常使用拉 ~