[转帖]apt-get update出现NO_PUBKEY问题解决

apt,get,update,出现,no,pubkey,问题,解决 · 浏览次数 : 0

小编点评

**解决方法:** 1. **获取公共密钥** - 使用 `gpg --keyserver keyserver.ubuntu.com --recv` 命令获取 `40976EAF437D05B5` 和 `3B4FE6ACC0B21F32gpg` 公钥。 - 在 `apt-key add` 命令中使用 `--insecure` 参数来允许不安全的键入。 2. **更新 apt-get 数据库** - 使用 `sudo apt-get update` 命令更新 apt-get 数据库。 - 这将允许你从可信任源下载软件包。 3. **添加公钥** - 使用 `apt-key add` 命令添加公钥。 - 使用 `sudo` 命令以管理员用户身份添加公钥。 **注意事项:** - 使用公钥更新 apt-get 数据库可能会导致安全性问题,因为您需要公开您的公钥。 - 请确保您信任从公钥中获取的服务器。 - 如果您不确定如何获取或添加公钥,请参阅官方文档或寻求帮助。

正文

apt-get update报错

root@2870e7cf8e74:/usr/tools# apt-get update
Ign:1 https://mirrors.aliyun.com/ubuntu trusty InRelease
Get:2 https://mirrors.aliyun.com/ubuntu trusty Release [58.5 kB]
Get:3 https://mirrors.aliyun.com/ubuntu trusty Release.gpg [933 B]
Ign:3 https://mirrors.aliyun.com/ubuntu trusty Release.gpg
Reading package lists... Done
W: GPG error: https://mirrors.aliyun.com/ubuntu trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'https://mirrors.aliyun.com/ubuntu trusty Release' 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.

    解决办法:

    将不可用的pubkey加到ubuntu服务器,从上面可以看到如下pubkey

    NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
    

      使用以上pubkey拼接如下命令

       gpg --keyserver keyserver.ubuntu.com --recv 40976EAF437D05B5
       gpg --export --armor 40976EAF437D05B5 |  apt-key add -
      

      gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
      gpg --export --armor 3B4FE6ACC0B21F32 | apt-key add -

        我的环境因为是docker中的Python环境 ,默认用户是root,所以不用加sudo,如果非root用户可能会需要切换用户获取权限。则命令如下:

        sudo gpg --keyserver keyserver.ubuntu.com --recv 40976EAF437D05B5
        sudo gpg --export --armor 40976EAF437D05B5 | sudo apt-key add -
        sudo gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
        sudo gpg --export --armor 3B4FE6ACC0B21F32 | sudo apt-key add -
        

          执行完以上命令后可以正常执行apt-update命令

          root@2870e7cf8e74:/usr/tools# apt-get update
          Ign:1 https://mirrors.aliyun.com/ubuntu trusty InRelease
          Get:2 https://mirrors.aliyun.com/ubuntu trusty Release [58.5 kB]
          Get:3 https://mirrors.aliyun.com/ubuntu trusty Release.gpg [933 B]
          Get:4 https://mirrors.aliyun.com/ubuntu trusty/main amd64 Packages [1350 kB]
          Get:5 https://mirrors.aliyun.com/ubuntu trusty/multiverse amd64 Packages [132 kB]
          Get:6 https://mirrors.aliyun.com/ubuntu trusty/restricted amd64 Packages [13.0 kB]
          Get:7 https://mirrors.aliyun.com/ubuntu trusty/universe amd64 Packages [5859 kB]
          Fetched 7414 kB in 22s (343 kB/s)
          Reading package lists... Done
          
            文章知识点与官方知识档案匹配,可进一步学习相关知识
            CS入门技能树Linux入门初识Linux23494 人正在系统学习中

            与[转帖]apt-get update出现NO_PUBKEY问题解决相似的内容: