强制更新来自未签名的存储库

我正在Ubuntu 16.04上使用来自Debian多媒体的未签名存储库。
deb http://www.deb-multimedia.org jessie main

安装deb-multimedia-keyring,我运行以下命令:
apt-get update && apt-get install deb-multimedia-keyring -y

这会产生一个错误。
W: GPG error: http://www.deb-multimedia.org jessie InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5C808C2B65558117
E: The repository 'http://www.deb-multimedia.org jessie 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.
8个回答

您可以在位于`/etc/apt/sources.list`的文件中设置选项。
deb [trusted=yes] http://www.deb-multimedia.org jessie main

颇受信赖的选项是关闭GPG检查。详细信息请参阅man 5 sources.list
您可以使用vim(或其他您喜欢的编辑器)在终端内编辑文件,也可以使用非终端编辑器如gedit。

我们如何从终端访问 sources.list - fuzzi
2它位于/etc/apt/sources.list。您可以在终端中使用vim(或您喜欢的其他编辑器)进行编辑,也可以使用非终端编辑器如gedit。 - Prathu Baronia
1“jessie main”是什么意思?我正在使用Lubuntu 20.04 LTS。 - ahorn
Jessie是发行版的名称,main是组件的名称。您可以在此处找到有关组件名称的信息:链接 - Prathu Baronia
6我的问题出在使用add-apt-repository添加的存储库上。请务必检查/etc/apt/sources.list.d/目录下是否存在任何.list文件,这些文件可能包含您尝试信任的源,此外还要检查/etc/apt/sources.list中的源。 - L Co
适用于Debian 11 Bullseye。 - JonathanDavidArndt

您可以通过使用以下选项绕过一些重要的安全保护。
--allow-unauthenticated

从apt-get的man页面中:

来自apt-get的man页面:

--allow-unauthenticated
    Ignore if packages can't be authenticated and don't prompt about
    it. This can be useful while working with local repositories, but
    is a huge security risk if data authenticity isn't ensured in
    another way by the user itself. The usage of the Trusted option for
    sources.list(5) entries should usually be preferred over this
    global override. Configuration Item:
    APT::Get::AllowUnauthenticated.

但是在更广泛地使用这个选项时要小心一点,这些保护措施是为了保护你的计算机而不是限制你的自由...
编辑
从较新版本的Ubuntu开始,可以使用--allow-insecure-repositories代替--allow-unauthenticated。
为了执行更新,命令应该是这样的。
sudo apt-get update --allow-insecure-repositories

1我使用的是Raspbian stretch,并且遇到了选项E: The repository 'http://ftp.de.debian.org/debian testing InRelease' is not signed. 我想要从Python 3.5升级到3.6。 - Timo
3告诉我,在执行 sudo apt-get update --allow-unauthenticated 时,“此选项不能与其他选项一起解释”。 - xeruf
76注意:截至2018年7月,这在Ubuntu 18.04中似乎不再起作用。 - Jay Taylor
@JayTaylor:我刚刚打开了一个全新的虚拟机,使用18.04版本,命令在这里完美运行。Pastebin链接:https://pastebin.com/ygLTnP1C - andrew.46
3有趣;也许在我尝试的那台机器上,除了我观察到的错误之外,可能还有其他不同的东西。无论如何,在sources.list中添加[trusted=yes]字段确实起作用了。感谢你的努力,@andrew.46 :) - Jay Taylor
48我在使用--allow-insecure-repositories时很幸运,通过这个答案 - kshakir
1我同意。事实上,我确实执行了“sudo apt-get update --allow-unauthenticated --allow-insecure-repositories”的命令,并且它运行成功了。可能是因为使用了--allow-insecure-repositories参数... - Brent Rittenhouse

另一个通用的解决方案可能是
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5C808C2B65558117

注意:我没有在这个存储库中测试过这个解决方案,但是我在Skype的存储库中测试过,并且运行得很好。
另一个适用于您情况的解决方案是安装密钥。
wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2012.05.05_all.deb -O deb-multimedia-keyring.deb
sudo dpkg -i multimedia-keyring_all.deb

如在完整的步行指南中所描述这里

这个解决方案有效...但我现在收到一个警告:“密钥存储在旧的 trusted.gpg 密钥环中(.etc.apt/trusted.gpg),请查看 apt-key 的 DEPRECATION 章节了解详情”。 - Joshua Clayton
建议的更改是将"| sudo apt-key add -"替换为"sudo tee /etc/apt/trusted.gpg.d/myrepo.asc"。 - Joshua Clayton

如果你想从一个将密钥打包并放在仓库内的仓库中获取一个软件包,而不是其他地方,那么使用dpkg下载和安装密钥/密钥环的包可能会非常烦人,并且很难以一种易于脚本化和可重复的方式进行操作。
下面的脚本不建议使用,如果你可以从密钥服务器安装密钥(如另一个答案中推荐的apt-key adv),或者如果你可以通过https从可信任的源下载并使用apt-key进行安装(例如wget https://trusted.key.site/my-trusted-key.gpg | sudo apt-key add -),但如果没有其他办法,你可以使用这个方法。
echo "deb http://your.repo.domain/repository/ $(lsb_release -c -s) universe" | sudo tee /etc/apt/sources.list.d/your-repo-name.list

sudo apt -o Acquire::AllowInsecureRepositories=true \
-o Acquire::AllowDowngradeToInsecureRepositories=true \
update

## if the 'apt update' above fails it is likely due to previously
## having the GPG key and repository on the system, you can clean
## out the old lists with `sudo rm /var/lib/apt/lists/your.repo.domain*`

apt-get -o APT::Get::AllowUnauthenticated=true install repo-keyring-pkgname

## If you ever run `sudo apt-key del your-repos-keyID`
## you may have to `sudo apt remove --purge repo-keyring-pkgname`
## Update should run without the GPG warnings now that the key is installed

apt-get update
apt-get install somepkg-from-repo

我最初做这个是因为i3在他们的sur5r软件库中也这样做,但后来我发现他们的密钥在keyserver.ubuntu.com列表中,所以我只需执行sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E3CA1A89941C42E6就可以避免所有额外的软件包麻烦。

这个答案在面对Ubuntu 18.04时似乎不完整。它试图通过说一些讨厌的话来惹我生气,比如 "发行版尚未有效(还有44分钟35秒才过期)。此仓库的更新将不会应用。" 即使删除了 /var/lib/apt/lists/* 的东西后仍然如此... - Jürgen Weigert
这只是一个镜像复制的问题,不应该影响软件包在仓库中的认证或签名。由于1804版本刚刚从测试版中发布,很多镜像正在努力追赶进度,因此镜像服务可能会指向尚未完全同步的服务器。 - dragon788

你可以从密钥服务器获取PUBLIC_KEY,并将其添加到apt-key中。假设密钥服务器是pgpkeys.mit.edu,你首先需要输入:
gpg --keyserver pgpkeys.mit.edu --recv-key KEY_IN_ERROR
gpg -a --export KEY_IN_ERROR | sudo apt-key add -

将错误消息中的KEY_IN_ERROR替换为实际的密钥,例如5C808C2B65558117。
另外,如果您真的想要添加一个未签名的软件源,可以在sources.list文件中的相应软件源条目中加入一个标志,如下所示:
deb [allow-insecure=yes] http://www.deb-multimedia.org jessie main

这对于想要为单个条目调整安全设置非常有用。

加上 [allow-insecure=yes] 对我有用 - akshit bhatia
太顺利了!谢谢。 - Jon

这有点重复了一个已经存在的答案,但是--allow-insecure-repositories--allow-unauthenticated只在某些组合中起作用。例如,在不安全的deadsnakes存储库中使用它们:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update --allow-insecure-repositories
sudo apt-get install python3.9* --allow-unauthenticated

在Ubuntu 20.04上无法工作。 - yegor256
我在一个基于Ubuntu 18.04的Linux Mint上尝试了这个答案,希望能对其他人有所帮助。 - xjcl

N:有关仓库创建和用户配置详细信息,请参阅 apt-secure(8) 手册页。
回答:
  1. ls /etc/apt/sources.list.d

然后尝试使用以下命令删除它们:

  1. sudo rm -i /etc/apt/sources.list.d/{output of 1}

对于每个仓库都要执行此操作。

例如:sudo rm -i /etc/apt/sources.list.d/wireshark-dev-ubuntu-stable-focal.list

然后尝试执行以下命令:

  1. sudo apt update

:)


这有点晚了,但我昨天才遇到这个问题。在从ubuntu.com获取的18.04 LTS的.iso文件安装时,我遇到了这个问题,而且ifconfig和其他网络工具也没有安装。无线网络无法使用。
这是在联想X140e笔记本上发生的,这种笔记本预装了Windows,并交给完成计算机课程的人使用。
我重新安装了几次,但结果并没有改善,可能是因为疯狂的定义适用于此。然后我将16.04 LTS放在U盘上并安装了它。我不得不在BIOS设置中进行一些调整才能安装。有趣的是,网络应用程序被安装了,而且无线网络找到了连接。起初,软件更新器也显示了相同的消息(存储库未签名等),但随后它告诉我有一个新版本可用,并问我是否要升级。
我尝试了一下,现在在18.04中一切都正常工作。你可以根据自己的理解来解释这个情况。我想补充说,这个页面上的其他答案都没有起作用。这就是为什么我提供这个“解决方案”的原因。

18.04不使用ifconfig,而是使用netplan。从16.04升级到18.04将保留ifconfig,并且可能对您的设备更好,但我不明白它与安装来自未签名存储库有什么关系。 - Paul
几乎可以肯定就是这样发生的。关键是,在安装了18.04裸机之后,更新无法正常工作:“存储库未签名”。为了使更新正常工作,我不得不先安装16.04,然后再升级到18.04。 - Wastrel
啊,好的,上面的故事中并没有那么清楚。但是现在在18.04版本上,你仍然可以安装来自未签名的软件源而不会出现任何错误信息吗?说实话,你可能希望收到这个消息,因为它可能表示某些问题存在,你可以根据上面的答案排除特定的软件源检查。 - Paul
是的,在按照升级程序后,一切都正常工作。令人困惑的是,18.04和16.04的.iso本身并没有标准存储库的签名。 - Wastrel