Ubuntu 22.04更新源出现Key is stored in legacy trusted.gpg keyring解决方案

    2022/07/13 12:51 下午 标签: #编程

    问题描述

    在升级Ubuntu 22.04后更新源出现如下警告:

    Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
    

    解决方案

    需要将出现该提示的GPG key存储到/usr/share/keyrings, 步骤如下:

    1. 查看现有key:
    $ 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>
    
    1. 假设有警告的Key为BE12 29CF(是Microsoft pub的后8位), 导出这个Key:
    $ sudo apt-key export BE1229CF | sudo gpg --dearmour -o /usr/share/keyrings/microsoft.gpg
    

    此时会出现如下提示:

    Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
    

    注意: 有部分文章指出导出到/etc/apt/trusted.gpg.d/microsoft.gpg, 虽然也可行, 但安全原因, Ubuntu社区并不推荐这样做. 此外, 导出的Key可以自由命名, 但是需要与步骤3相对应, 这里命名为microsoft.

    1. 用vim更新警告相关的apt源文件, 位置为/etc/apt/sources.list.d/, 假设文件为microsoft.list, 用Vim打开, 并如下添加signed-by标签关联步骤2导出的Key文件:
    deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge/ stable main
    
    1. 更新源: sudo apt update, 可以看到警告消失了, 此时可以移除原始key:
    $ sudo apt-key del BE1229CF
    

    参考资料

    Stack Exchange: Key is stored in legacy trusted.gpg keyring