这条 apt 错误消息(“下载是以 root 身份未经沙箱执行...”)是什么意思?

Jul*_*urs 52 synaptic permissions apt

我在 Synaptic Manager 中更新后得到它

我最近从 16.10 全新安装了 Ubuntu 17.04。

错误信息:-

W: Download is performed unsandboxed as root as file '/var/cache/apt/archives/partial/samba-libs_2%3a4.5.8+dfsg-0ubuntu0.17.04.1_i386.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
Run Code Online (Sandbox Code Playgroud)

Flo*_*sch 43

通常 apt 使用用户_apt下载包。在您的情况下_apt,没有对任/var/cache/apt/archives/partial/一文件或现有文件的写权限,/var/cache/apt/archives/partial/samba-libs_2%3a4.5.8+dfsg-0ubuntu0.17.04.1_i386.deb因此它将文件下载为root.

确保/var/cache/apt/archives/partial/它下面的所有内容都是可写的_apt,例如通过运行

sudo chown -Rv _apt:root /var/cache/apt/archives/partial/
sudo chmod -Rv 700 /var/cache/apt/archives/partial/
Run Code Online (Sandbox Code Playgroud)

  • 我在使用 vagrant VM 的挂载文件夹时遇到了这个问题,因此挂载的文件夹始终属于无法更改的用户 `vagrant`。我怎样才能在那里解决这个问题?也许只是禁用警告,因为在我的测试 VM 中,如果 apt 由 root 运行,这不是问题 (3认同)
  • 这里更简单的解决方案:https://askubuntu.com/a/1416892/297529 (2认同)

Ell*_*iew 13

tl;dr忽略与 apt 相关的“W: ... _apt ...”警告行。它们是非致命的,并且在大多数情况下您无法解决此问题,无论有没有警告,您都会得到相同的结果。


即使在这里实施了 Florian Diesch 的好答案,我仍然收到此警告。当我尝试使用 下载源代码时apt-get source ...,即使我尝试以 root 身份下载,如使用sudosu,(Debian 10.4 和 apt 1.8.2.1),我也会得到它。

网络上充斥着有关此警告消息的问题,并提供了许多不同的建议解决方案。很明显,自从 apt 工具被更改为_apt用于沙盒的安全操作以来,很多人一直在使用它。

似乎在进行此_apt更改后,一大堆尚未完全修复的东西就坏了。


让我们再次分解这个问题:

首先,带有W: 前缀的apt 结果行只是警告。警告是异常的东西,但不会阻止程序继续运行。(参考:库萨兰南达

正如弗洛里安指出的那样,“apt 使用用户_apt下载软件包”。似乎在这种情况下,named 的用户root根本不能做named 用户_apt可以做的事情。


部分解决方案,(您真的不想使用):

您必须确保您所在的文件夹(即放置源的位置)归_apt:root. 所以如果你$ mkdir temp; sudo chown _apt:root temp; sudo -s# cd temp; apt-get source ...警告不会出现。

当然,一旦完成,您就必须为这个基本文件夹赋予更合理的所有权,因为被 _apt:root 拥有是很奇怪的。

无论有没有警告消息,结果是否相同?

# -- TEST 1:  get source into folder owned by user ------------
$ mkdir temp1;
$ cd temp1; sudo apt-get source gnupg2     # gives warning message:
...
W: Download is performed unsandboxed as root as file 'gnupg2_2.2.12-1+deb10u1.dsc' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)


# -- TEST 2:  get source into folder owned by root ------------
$ cd ..; sudo -s
# mkdir temp2;
# cd temp2;      apt-get source gnupg2     # gives warning message:
...
W: Download is performed unsandboxed as root as file 'gnupg2_2.2.12-1+deb10u1.dsc' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)


# -- TEST 3:  get source into folder owned by _apt:root -------
# cd ..
# mkdir temp3; chown _apt:root temp3
# cd temp3;      apt-get source gnupg2     #    no warning message now!


# == COMPARE the results ======================================
$ cd ..
$ sudo diff -r temp1 temp2                 # no differences
$ sudo diff -r temp1 temp3                 # no differences
Run Code Online (Sandbox Code Playgroud)

所以无论有没有警告,结果都是一样的!


我忍不住补充说,这里讨论的APT并不是指最可怕的事情:高级持续性威胁



我之前的回答在这里(是)

...直到现在,已经为我解决了这个问题,但我现在可以看到,是不够的:

用这个修复它:

sudo chown -R _apt:root /var/lib/apt/lists
Run Code Online (Sandbox Code Playgroud)


  • 列表目录本身,而不是它的内容,需要有业主_apt(即这是一个重要的文件分支,默认根所有权失败!)

  • 我可能在删除列表时出现了这个问题,然后sudo mkdir lists; apt update按照其他地方的建议重新制作它。

  • 此外,此解决方案可能是任何其他解决方案的补充,因为我首先尝试了许多其他解决方案


Debian 10.2 延伸版。

# apt-get --version
apt 1.8.2 (amd64)
Supported modules:
*Ver: Standard .deb
*Pkg:  Debian dpkg interface (Priority 30)
 Pkg:  Debian APT solver interface (Priority -1000)
 Pkg:  Debian APT planner interface (Priority -1000)
 S.L: 'deb' Debian binary tree
 S.L: 'deb-src' Debian source tree
 Idx: Debian Source Index
 Idx: Debian Package Index
 Idx: Debian Translation Index
 Idx: Debian dpkg status file
 Idx: Debian deb file
 Idx: Debian dsc file
 Idx: Debian control file
 Idx: EDSP scenario file
 Idx: EIPP scenario file
Run Code Online (Sandbox Code Playgroud)

  • 一行:`mv package.deb /tmp; cd /tmp;sudo apt install package.deb` (2认同)

小智 5

我在 Debian Stretch(全新安装的 Xen VM)上也遇到了这个问题,结果是 sudo 的问题。

无法在机器上执行任何 sudo。

更准确地说,系统的根/目录在700(drwx------)。一个chmod 755 /固定它。