将包直接复制到 /var/cache/apt/archives/ 是否安全?

将包直接复制到 /var/cache/apt/archives/ 是否安全?

全新安装后,我不想从 Debian 镜像下载一些 .deb 软件包,而是直接将文件从拇指驱动器复制到 /var/cache/apt/archives/

它会提供相同的安全保证(以防文件损坏)吗?换句话说,即使从缓存中获取文件,还是仅在完成下载后才检查文件哈希值?

我应该对缓存的 .deb 使用特定的 chmod / chown 吗?

版本 2.2.4 / Debian 11

答案1

是的,apt在使用它们之前,会根据已发布哈希值的本地副本检查其缓存中的包文件,即使它们不是刚刚下载的。

要查看这一点,请下载旧版本hello(因此测试使用有效的包,只是不是正确的包),重命名它(因此它假装是当前版本),然后安装它:

$ wget http://snapshot.debian.org/archive/debian/20141106T162403Z/pool/main/h/hello/hello_2.9-2_amd64.deb
[…]
$ sudo mv hello_2.9-2_amd64.deb /var/cache/apt/archives/hello_2.10-2_amd64.deb
$ sudo apt install hello
[…]
The following NEW packages will be installed:
  hello
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 56.1 kB of archives.
After this operation, 287 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 hello amd64 2.10-2 [56.1 kB]
Fetched 56.1 kB in 2s (36.3 kB/s)
[…]

apt默默地丢弃无效的包文件并下载一个新的。检查已安装软件包的更改日志 ( /usr/share/doc/hello/changelog.Debian.gz) 确认已安装软件包是版本 2.10-2,而不是手动下载的旧版本。

(如果您尝试这样做,请随后清除该软件包。它很小且无害,但没有必要保留它。)

据我所知,缓存中的包文件不需要任何特定的权限。

为了确保哈希值正确,您应该apt update在从填充的缓存安装包之前运行。

相关内容