如何为 Microsoft 软件包添加 APT 密钥

如何为 Microsoft 软件包添加 APT 密钥

我正在尝试安装一些软件包Microsoft APT 存储库(因为我非常讨厌 Snap!)但我似乎无法添加它的键:

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
OK

它显示 OK,但是键不起作用:

$ sudo apt update
[...]
Err:7 https://packages.microsoft.com/repos/vscode stable InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
Reading package lists... Done
W: GPG error: https://packages.microsoft.com/repos/vscode stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/repos/vscode stable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

我还尝试从 apt-get 打印的 NO_PUBKEY id 开始检索密钥:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EB3E94ADBE1229CF
Executing: /tmp/apt-key-gpghome.q9IjlmqKv9/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv EB3E94ADBE1229CF
gpg: key EB3E94ADBE1229CF: "Microsoft (Release signing) <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

它说“没有改变”,事实上,什么都没有改变。

如果我检查输出,apt-key list我会发现除了 Microsoft 的密钥之外,所有第三方密钥都有一个sub rsa4096。这就是它不起作用的原因吗?

$ sudo apt-key list 
/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2017-05-08 [SCEA]
      1EDD E2CD FC02 5D17 F6DA  9EC0 ADAE 6AD2 8A8F 901A
uid           [ unknown] Sublime HQ Pty Ltd <[email protected]>
sub   rsa4096 2017-05-08 [S]

pub   rsa4096 2016-04-12 [SC]
      EB4C 1BFD 4F04 2F6D DDCC  EC91 7721 F63B D38B 4796
uid           [ unknown] Google Inc. (Linux Packages Signing Authority) <[email protected]>
sub   rsa4096 2019-07-22 [S] [expires: 2022-07-21]

pub   rsa4096 2014-06-13 [SC]
      9FD3 B784 BC1C 6FC3 1A8A  0A1C 1655 A0AB 6857 6280
uid           [ unknown] NodeSource <[email protected]>
sub   rsa4096 2014-06-13 [E]

pub   rsa2048 2015-10-28 [SC]
      BC52 8686 B50D 79E3 39D3  721C EB3E 94AD BE12 29CF
uid           [ unknown] Microsoft (Release signing) <[email protected]>

[...]

我该如何解决这个问题?

Ubuntu 20.04 焦点

答案1

没关系,错误信息有点误导。

问题是我的 sources.list 文件(我从微软自己的说明) 指向一个不存在的密钥文件:

deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main

signed-by从方括号中删除了该选项,一切正常。

答案2

我跑了这个

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

并且一切正常。

https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu。您可以ctrl + f这样做:22.04 (Microsoft package feed)您将找到来自微软的说明。

答案3

这个问题很老了,但问题仍然存在。我试图在 Ubuntu 20.04 上安装 MSSQL 2022,遇到了这个问题。无论出于什么原因,sudo wget https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc都没有将文件复制到指定的目标,而是复制到当前文件夹。目标文件是空的,所以我只是将它复制到它应该在的位置,存储库就成功添加了。

答案4

请尝试以下步骤。

apt-key 列表 apt-key del “Microsoft 公钥” curl -fsSLhttps://packages.microsoft.com/keys/microsoft.asc| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/packages.microsoft.gpg apt 更新

相关内容