Linux fake root,fakeroot vs sudo

fakeroot vs sudo

发布时间:2008-10-15 00:14:54来源:红联作者:Montun

1.sudo是一个setuid程序,而fakeroot不是。

2.sudo真正地给与root权限,而fakeroot不会,它只会欺骗程序看起来像是以root身份执行得到的效果。

3.fakeroot最初是为了创建debian包使用的,Fedora上也有fakeroot包,但不知为何找不到其man手册……

4.fakeroot的文档中提到:

fakeroot works by replacing the file manipulation library functions

(chmod(2), stat(2) etc.) by ones that simulate the effect the real

library functions would have had, had the user really been root. These

wrapper functions are in a shared library /usr/lib/libfakeroot.so*

which is loaded through the LD_PRELOAD mechanism of the dynamic loader.

[...]

Internally, faked keeps track of all files which have had operations

done on them that the user would not normally be able to do, in order to

fake the effect later.

For example, if you create a device node, faked will actually create an

empty file, but remember that it was a device node (along with the

relevant details) so that if you subsequently do an “ls -l”, you’ll see

it as a device node.

所以fakeroot并不会对静态链接的程序起作用。

5.fakeroot使用了很多trick,不信的话查看其源代码(看看里面那个awk脚本!)。