在阅读了这个问题的一些非常好的答案后,我仍然不明白为什么要假装自己是 root 而没有获得实际 root 的任何好处。
到目前为止,我可以收集到的是,fakeroot 用于在解压缩/tar'ed 时将所有权授予需要为 root 的文件。我的问题是,为什么你不能用 chown 做到这一点?
此处的 Google Groups 讨论指出,您需要 fakeroot 来编译 Debian 内核(如果您想从非特权用户那里执行此操作)。我的评论是,您需要成为 root 才能编译的原因可能是因为没有为其他用户设置读取权限。如果是这样,fakeroot 允许编译是否违反安全(这意味着 gcc 现在可以读取 root 的文件)?
这里的这个答案描述了实际的系统调用是使用用户的真实 uid/gid 进行的,那么 fakeroot 在哪里有帮助?
fakeroot 如何阻止 Linux 上不需要的权限提升?如果 fakeroot 可以欺骗 tar 制作一个属于 root 的文件,为什么不使用 SUID 做类似的事情呢?
从我收集到的信息来看,fakeroot 在您想要更改您构建为 root 的任何包文件的所有者时非常有用。但是你可以用 chown 来做到这一点,所以我对这个组件应该如何使用的理解有欠缺吗?
我有一个脚本,它通过运行准备安装映像debootstrap
,对文件进行一些修改,然后将文件复制到由文件备份的磁盘映像。
这在 下有效root
,但我希望能够在没有root
特权的情况下运行脚本,因为它确实不需要任何特权资源。我以为我会使用 运行整个脚本fakeroot
,但debootstrap
失败了
W: Failure trying to run: chroot /tmp/tmp..... mount -t proc proc /proc
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题?
在 Debian 上,运行时:
$ fakeroot cdebootstrap stable /tmp/foo
Run Code Online (Sandbox Code Playgroud)
cdebootstrap 下载软件包,但是当它必须解压它们时,我收到此错误:
E: Failed to unshare: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
如何以非 root 身份运行 cdebootstrap?
取消共享手册中的这一部分似乎相关,但我不确定如何:
EPERM (since Linux 3.9)
CLONE_NEWUSER was specified in flags and the caller is in a
chroot environment (i.e., the caller's root directory does not
match the root directory of the mount namespace in which it
resides).
Run Code Online (Sandbox Code Playgroud) 我不明白为什么当我chmod
使用fakeroot
.
最初,该文件具有以下权限:
-rwxr-xr-x a.txt*
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 chmod 更改文件的权限时,它工作正常:
chmod 111 a.txt
---x--x--x a.txt*
Run Code Online (Sandbox Code Playgroud)
当我用fakeroot
它运行它时,它似乎不能正常工作。它正确设置了组和其他的权限,但不是为用户设置的。无论chmod
命令中的第一个值是什么,读取和写入的权限都已设置。
fakeroot chmod 111 a.txt
-rwx--x--x a.txt*
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
在 fakeroot 环境中使用chown(2)时,我遇到了奇怪的行为。以下最小程序说明了这个问题:
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
int main() {
//choose a reasonably unique filename
char path[30];
sprintf(path, "./file-%d", getpid());
//create file
close(creat(path, 0644));
//chown to some random UID/GID
chown(path, 4444, 4444);
//stat again (result can be seen in strace below)
struct stat s;
stat(path, &s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
假设是main.c
。现在我在 a 中运行以下内容fakeroot bash
:
$ gcc -o main main.c
$ strace -v ./main
...
creat("./file-10872", 0644) = 3
close(3) = 0 …
Run Code Online (Sandbox Code Playgroud)