更新系统时 apt-key 弃用警告:“密钥存储在旧版 trust.gpg 密钥环中”

mat*_*igo 177 apt keyrings 21.10

最近我在运行时注意到一些问题,apt系统会警告我密钥环已弃用:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: https://packages.microsoft.com/repos/edge/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://download.sublimetext.com/apt/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Run Code Online (Sandbox Code Playgroud)

这并不会阻止我执行更新,但我宁愿在更新系统时看不到这一点。未来我们应该如何存储可信的 GPG 密钥?

mat*_*igo 253

解决此问题的一种方法是从已弃用的密钥环中导出 GPG 密钥并将其存储在/usr/share/keyrings. 幸运的是,这并不太难:

  1. 打开终端(如果尚未打开)

  2. 列出现有的键:

    $ sudo apt-key list
    Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
    /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 <support@sublimetext.com>
    sub   rsa4096 2017-05-08 [S]
    
    pub   rsa2048 2015-10-28 [SC]
          BC52 8686 B50D 79E3 39D3  721C EB3E 94AD BE12 29CF
    uid           [ unknown] Microsoft (Release signing) <gpgsecurity@microsoft.com>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 从这里,我们可以导出密钥:

    sudo apt-key export BE1229CF | sudo gpg --dearmor -o /usr/share/keyrings/microsoft.gpg
    
    Run Code Online (Sandbox Code Playgroud)

    注意:BE1229CF值来自代码的最后 8 个字符pub

    可能会出现以下消息:

    Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
    
    Run Code Online (Sandbox Code Playgroud)
  4. 现在我们可以更新存储库的 apt 源文件(例如/etc/apt/sources.list.d/microsoft.list),添加一个signed-by标签:

    deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge/ stable main
    
    Run Code Online (Sandbox Code Playgroud)
  5. 更新apt以确认消息已消失:

    sudo apt update
    ...
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    All packages are up-to-date.
    W: https://download.sublimetext.com/apt/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
    
    Run Code Online (Sandbox Code Playgroud)
  6. 删除原来的签名:

    sudo apt-key del BE1229CF
    
    Run Code Online (Sandbox Code Playgroud)

这可以通过每条警告消息来完成。一旦完成,apt就不会再抱怨。

  • 相关问答:[哪些命令(确切地)应该替换已弃用的 apt-key?](https://askubuntu.com/questions/1286545/what-c​​ommands-exactly-should-replace-the-deprecated-apt-key) (8认同)
  • 您应该使用 `/usr/share/keyrings`,而不是 `/etc/apt/keyrings` - https://wiki.debian.org/DebianRepository/UseThirdParty (7认同)
  • 关于:“注意:BE1229CF 值来自 pub 代码的最后 8 个字符。”——您能否详细说明一下,“BE1229CF”显然不在屏幕上的任何位置。你做了一些位运算来获得这个值还是什么? (6认同)
  • @MartinMucha 看一下第 1 项中的代码块。您将在倒数第二行看到“BE12 29CF”。这就是它的来源 (3认同)
  • 如果应用程序自动配置 .list 文件,从而每次都恢复更改,该怎么办?例如,可以在 slack.list 文件中找到此警告: `### THIS FILE IS AUTOMATICALLY CONFIGURED ### # You may comment out this Entry, but any other optimizations might be loss.` 如何绕过这个问题在这种情况下,即确保“签名者”添加被保留并且不会被 apt 源维护者恢复? (2认同)

小智 164

尝试这个

cd /etc/apt
sudo cp trusted.gpg trusted.gpg.d
Run Code Online (Sandbox Code Playgroud)

  • 对于审阅者:这是有道理的,因为“/etc/apt/trusted.gpg”是一个单一密钥环的旧形式。在现代的 apt 中,每个密钥环都单独存储在 /etc/apt/trusted.gpg.d 中。将旧数据库移至“/etc/apt/trusted.gpg.d/”是手动读取存储库并让 apt 自动更新密钥存储的解决方法。这是一种解决方法,尽管它不是最好的也不是最受 APT 首选的解决方案,但它仍然是一种解决方案。 (19认同)
  • 某件事有效并不等于它是一个好的或可行的解决方案。根据“trusted.gpg”中存储的密钥,这可能是一个安全漏洞。 (13认同)
  • 乌班图22.04。也为我工作过。谢谢.. (4认同)
  • 两名首次发帖者评论(作为答案)这对他们有用。这篇文章不应该被删除。我代表两位新用户投票这个答案。 (2认同)

hey*_*ema 40

sudo apt update修复这些由...生成的警告消息的简单方法

W: https://linux.teamviewer.com/deb/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://apt.keepsolid.com/ubuntu/dists/groovy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://linux.dropbox.com/ubuntu/dists/disco/Release.gpg: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://download.virtualbox.org/virtualbox/debian/dists/hirsute/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://download.opensuse.org/repositories/home:/IBBoard:/cawbird/xUbuntu_22.04/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://ppa.launchpad.net/solaar-unifying/stable/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://ppa.launchpad.net/team-xbmc/ppa/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: http://ppa.launchpad.net/yannubuntu/boot-repair/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Run Code Online (Sandbox Code Playgroud)

注意:这些警告消息可以由“其他软件”选项卡中任何启用的存储库或 ppa生成Software & Updates

修复示例:


对于此警告消息sudo apt update...

W: http://ppa.launchpad.net/team-xbmc/ppa/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Run Code Online (Sandbox Code Playgroud)

我们查看sudo apt-key list并找到 xbmc 的这个条目...

pub   rsa1024 2009-01-20 [SC]
      1897 01DA 570C 56B9 488E  F60A 6D97 5C47 91E7 EE5E
uid           [ unknown] Launchpad PPA for XBMC for Linux
Run Code Online (Sandbox Code Playgroud)

然后我们使用上面的最后 8 个数字字符将此条目转换为 .gpg 文件...

sudo apt-key export 91E7EE5E | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/team-xbmc.gpg
Run Code Online (Sandbox Code Playgroud)

对 生成的每条警告消息重复上述命令sudo apt update

注意:部分摘自此处此处已接受的答案。


小智 7

考虑到提供的所有好的建议,我制作了一个助手 oneliner 来自动化所有键的过程:

sudo apt-key list 2>&1 | grep -E '(trusted.gpg.d)' -A 3 | grep -v '^\-\-' | grep -v '^pub ' | sed 's@.*/trusted.gpg.d/\(.*\)@\1@g' | awk 'NR%2{printf "%s ",$0;next;}1' | awk '{print "sudo apt-key export "$10$11" | sudo gpg --dearmour -o /usr/share/keyrings/"$1}' | xargs -I{} eval("{}")
Run Code Online (Sandbox Code Playgroud)

  • 对我有用,但我需要稍微改变一下: `sudo apt-key list 2&gt;&amp;1 | grep -E '\/(trusted.gpg.d)' -A 3 | grep -E '\/(trusted.gpg.d)' -A 3 | grep -v '^\-\-' | grep -v '^\-\-' | grep -v '^pub ' | grep -v '^pub ' | /bin/sed 's@.*/trusted.gpg.d/\(.*\)@\1@g' | /bin/awk 'NR%2{printf "%s ",$0;下一个;}1' | /bin/awk '{print "sudo apt-key export "$10$11" | sudo gpg --dearmour -o /usr/share/keyrings/"$1}' | xargs -I'{}' bash -c "eval '{}'"`。在第一个 grep 中,您需要使用正则表达式 `'\/(trusted.gpg.d)'` 来代替,或者与警告消息匹配。最后,我需要更改 xargs 执行。 (4认同)