GPG错误:https://apt.releases.hashicorp.com Bionic InRelease:由于公钥不可用,无法验证以下签名

Thi*_*age 26 apt terraform hashicorp

我运行此命令来更新 ubuntu VM 中的软件包。

sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

它最后给了我以下错误。

Err:5 https://apt.releases.hashicorp.com bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXXXXXX
Fetched 12.0 kB in 1s (10.4 kB/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://apt.releases.hashicorp.com bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXXXXXX
W: Failed to fetch https://apt.releases.hashicorp.com/dists/bionic/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXXXXXX
W: Some index files failed to download. They have been ignored, or old ones used instead.
Run Code Online (Sandbox Code Playgroud)

这是什么意思以及如何解决它?

Thi*_*age 75

这意味着该 HashiCorp 存储库的 gpg 密钥在 apt-key 数据库中不可用。

作为修复,可以使用以下命令重新添加它。

# GPG is required for the package signing key
sudo apt install gpg

# Download the signing key to a new keyring
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

# Verify the key's fingerprint
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint

# The fingerprint must match 798A EC65 4E5C 1542 8C8E 42EE AA16 FCBC A621 E701, which can also be verified at https://www.hashicorp.com/security under "Linux Package Checksum Verification".

# Add the HashiCorp repo
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

# apt update successfully
sudo apt update
Run Code Online (Sandbox Code Playgroud)

请注意,这些命令取自Hashicorp 的官方打包指南

  • /etc/apt/sources.list.d/hashicorp.list 的更改是正确的,但是我还有一个遗留列表文件 /etc/apt/sources.list.d/terraform.list 需要按照 https:// 删除/github.com/hashicorp/terraform/issues/30911 (4认同)
  • NO_PUBKEY AA16FCBCA621E701 chmod 644 /usr/share/keyrings/hashicorp-archive-keyring.gpg (3认同)