如何解决 APT 软件源连接失败 Err: http://security.debian.org/debian-security stretch/updates Release.gpg: The fo

🦉🐯猫头虎运维小课堂:如何解决 APT 软件源连接失败 Err: http://security.debian.org/debian-security stretch/updates Release.gpg:

The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY🛠️

博主猫头虎的技术世界

🌟 欢迎来到猫头虎的博客 — 探索技术的无限可能!

专栏链接

🔗 精选专栏

领域矩阵

🌐 猫头虎技术领域矩阵
深入探索各技术领域,发现知识的交汇点。了解更多,请访问:

在这里插入图片描述

嗨!大家好,这里是猫头虎的运维小课堂。今天我们要聊聊一个在运维工作中非常普遍的问题,那就是 APT 软件源连接失败。无论你是新手还是老司机,当你遇到以下错误时:

Err: http://security.debian.org/debian-security stretch/updates Release.gpg:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY

别慌!跟着猫头虎的指南,逐步找出问题并解决它吧!🥳

📋 问题描述

  • 场景:在使用 APT 工具(如 apt-getapt update)更新 Debian 系统或安装软件时,APT 会尝试通过签名校验包的完整性与安全性。然而,如果源的公钥不可用或失效,APT 将无法验证该源,最终导致软件包无法正常更新或安装。

  • 症状:终端中出现类似 NO_PUBKEY 的错误信息,表示公钥缺失或损坏。

🔎 原因剖析

为什么会出现这个错误呢?常见的原因包括:

  1. 过时的公钥:软件源的公钥可能在你添加它之后的某个时间失效了。
  2. 缺失的公钥:你添加的软件源可能需要特定的公钥,但你并未导入它。
  3. 被劫持的源:恶意软件劫持或篡改源文件,导致签名错误。

无论原因如何,APT 都将无法信任并更新这些软件源。

🛠️ 解决方案

更换国内镜像源

国外源连接不稳定是导致 APT 软件源连接失败的一个主要原因。我们可以更换成国内的镜像源,常见的有清华大学源或阿里云镜像站。

步骤如下

  1. 备份原有的 sources.list 文件

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 编辑 sources.list 文件

    sudo nano /etc/apt/sources.list
    

    使用你喜欢的编辑器打开 sources.list 文件,将内容替换为如下内容:

    清华大学源

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
    

    阿里云源

    deb http://mirrors.aliyun.com/debian/ stretch main contrib non-free
    deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free
    deb http://mirrors.aliyun.com/debian/ stretch-updates main contrib non-free
    
  3. 更新包列表

    sudo apt update
    

    这一步确认 APT 使用新的国内源成功地拉取了软件包信息列表。

手动导入公钥

如果你仍然偏好使用原有的国外源,请确保你导入了正确的公钥。

步骤如下

  1. 获取源的 GPG 公钥:通常镜像站会提供一个可以直接下载的 .gpg 文件或提供指令。以 Debian 官方源为例:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553
    

    将上述命令中的密钥 ID 8B48AD6246925553 替换为你需要的密钥 ID。

  2. 更新包列表

    sudo apt update
    

    如果没有错误信息,问题已解决。

❓ 常见问答

Q1:更换国内源还是出现连接失败的问题怎么办?

A1:确保网络连接正常,可以尝试手动 Ping 镜像站点以确认网络通畅。此外,国内源偶尔也会有临时故障,建议耐心等待或切换到其他源。

Q2:我可以删除 NO_PUBKEY 提示的源继续更新吗?

A2:这并不安全!公钥验证是确保软件包未被篡改的重要机制。直接删除源将可能导致下载不受信任的包,请谨慎行事。

Q3:是否需要定期更换或更新镜像源?

A3:定期更新镜像源有助于确保你获得最新的软件包,但频繁更换并非必要。只需确保当前源稳定且没有错误即可。

📊 总结

  • APT 软件源连接失败通常与网络问题、公钥失效或软件源问题相关。
  • 更换到国内的稳定镜像站可以解决大多数问题。
  • 手动导入或更新公钥可以修复失效的密钥。

🔮 未来发展趋势

APT 是 Linux 生态的重要组成部分,未来发展趋势包括:

  • 更全面的镜像源管理工具。
  • 更加智能化的自动公钥验证和管理。
  • 使用新的校验算法以提高软件包完整性。

想获取更多更新资讯或加入技术讨论,欢迎加入我们的领域社群!📢

在这里插入图片描述

👉 更多信息:有任何疑问或者需要进一步探讨的内容,欢迎点击下方文末名片获取更多信息。我是猫头虎博主,期待与您的交流! 🦉💬

🚀 技术栈推荐
GoLang, Git, Docker, Kubernetes, CI/CD, Testing, SQL/NoSQL, gRPC, Cloud, Prometheus, ELK Stack

💡 联系与版权声明

📩 联系方式

  • 微信: Libin9iOak
  • 公众号: 猫头虎技术团队

⚠️ 版权声明
本文为原创文章,版权归作者所有。未经许可,禁止转载。更多内容请访问猫头虎的博客首页

点击下方名片,加入猫头虎领域社群矩阵。一起探索科技的未来,共同成长。

  • 37
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
root@6527d9173397:/# apt update Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Temporary failure resolving 'security.ubuntu.com' Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease Temporary failure resolving 'archive.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... Done Building dependency tree... Done Reading state information... Done All packages are up to date. W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease Temporary failure resolving 'security.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead.
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值