Linux "fakeroot" Command Line Options and Examples
run a command in an environment faking root privileges for file manipulation

fakeroot runs a command in an environment wherein it appears to have root privileges for file manipulation. This is useful for allowing users to create archives (tar, ar, .deb etc.


Usage:

fakeroot [-l|--lib library] [--faked faked-binary] [-i load-file] [-s save-file] [-u|--unknown-is-real ] [-b|--fd-base ] [-h|--help ]
    [-v|--version ] [--] [command]






Command Line Options:

-l
Specify an alternative wrapper library.
fakeroot -l ...
--faked
Specify an alternative binary to use as faked.
fakeroot --faked ...
--]
Any command you want to be ran as fakeroot. Use ‘--’ if in the command you have other options that may confuse fakeroot'soption parsing.
fakeroot --] ...
-s
Save the fakeroot environment to save-file on exit. This file can be used to restore the environment later using -i. However,this file will leak and fakeroot will behave in odd ways unless you leave the files touched inside the fakeroot alone whenoutside the environment. Still, this can be useful. For example, it can be used with rsync(1) to back up and restore wholedirectory trees complete with user, group and device information without needing to be root. See /usr/share/doc/fake‐root/README.saving for more details.
fakeroot -s ...
-i
Load a fakeroot environment previously saved using -s from load-file. Note that this does not implicitly save the file, use
fakeroot -i ...
-u
Use the real ownership of files previously unknown to fakeroot instead of pretending they are owned by root:root.
fakeroot -u ...
-v
EXAMPLESHere is an example session with fakeroot. Notice that inside the fake root environment file manipulation that requires root privi‐leges succeeds, but is not really happening.$ whoamijoost$ fakeroot /bin/bash# whoamiroot# mknod hda3 b 3 1# ls -ld hda3brw-r--r-- 1 root root 3, 1 Jul 2 22:58 hda3# chown joost:root hda3# ls -ld hda3brw-r--r-- 1 joost root 3, 1 Jul 2 22:58 hda3# ls -ld /drwxr-xr-x 20 root root 1024 Jun 17 21:50 /# chown joost:users /# chmod a+w /# ls -ld /drwxrwxrwx 20 joost users 1024 Jun 17 21:50 /# exit$ ls -ld /drwxr-xr-x 20 root root 1024 Jun 17 21:50 //$ ls -ld hda3
fakeroot -v ...
-rw-r--r--
Only the effects that user joost could do anyway happen for real.fakeroot was specifically written to enable users to create Debian GNU/Linux packages (in the deb(5) format) without giving them rootprivileges. This can be done by commands like dpkg-buildpackage -rfakeroot or debuild -rfakeroot (actually, -rfakeroot is default indebuild nowadays, so you don't need that argument).SECURITY ASPECTSfakeroot is a regular, non-setuid program. It does not enhance a user's privileges, or decrease the system's security.FILES/usr/lib/*/libfakeroot-*.so The shared library containing the wrapper functions.ENVIRONMENTFAKEROOTKEYThe key used to communicate with the fakeroot daemon. Any program started with the right LD_PRELOAD and a FAKEROOTKEY of arunning daemon will automatically connect to that daemon, and have the same "fake" view of the file system's permissions/own‐erships. (assuming the daemon and connecting program were started by the same user).LD_LIBRARY_PATHLD_PRELOADFakeroot is implemented by wrapping system calls. This is accomplished by setting LD_LIBRARY_PATH=/usr/lib/fakeroot andLD_PRELOAD=libfakeroot.so.0. That library is loaded before the system's C library, and so most of the library functions areintercepted by it. If you need to set either LD_LIBRARY_PATH or LD_PRELOAD from within a fakeroot environment, it should beset relative to the given paths, as in LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/foo/bar/LIMITATIONSLibrary versionsEvery command executed within fakeroot needs to be linked to the same version of the C library as fakeroot itself.open()/create()fakeroot doesn't wrap open(), create(), etc. So, if user joost does eithertouch foofakerootls -al fooor the other way around,fakeroottouch fools -al foofakeroot has no way of knowing that in the first case, the owner of foo really should be joost while the second case it shouldhave been root. For the Debian packaging, defaulting to giving all "unknown" files uid=gid=0, is always OK. The real wayaround this is to wrap open() and create(), but that creates other problems, as demonstrated by the libtricks package. Thispackage wrapped many more functions, and tried to do a lot more than fakeroot . It turned out that a minor upgrade of libc(from one where the stat() function didn't use open() to one with a stat() function that did (in some cases) use open()),would cause unexplainable segfaults (that is, the libc6 stat() called the wrapped open(), which would then call the libc6stat(), etc). Fixing them wasn't all that easy, but once fixed, it was just a matter of time before another function startedto use open(), never mind trying to port it to a different operating system. Thus I decided to keep the number of functionswrapped by fakeroot as small as possible, to limit the likelihood of ‘collisions’.GNU configure (and other such programs)fakeroot, in effect, is changing the way the system behaves. Programs that probe the system like GNU configure may get con‐fused by this (or if they don't, they may stress fakeroot so much that fakeroot itself becomes confused). So, it's advisablenot to run "configure" from within fakeroot. As configure should be called in the "debian/rules build" target, running"dpkg-buildpackage -rfakeroot" correctly takes care of this.BUGSIt doesn't wrap open(). This isn't bad by itself, but if a program does open("file", O_WRONLY, 000), writes to file "file", closesit, and then again tries to open to read the file, then that open fails, as the mode of the file will be 000. The bug is that if rootdoes the same, open() will succeed, as the file permissions aren't checked at all for root. I choose not to wrap open(), as open() isused by many other functions in libc (also those that are already wrapped), thus creating loops (or possible future loops, when theimplementation of various libc functions slightly change).COPYINGfakeroot is distributed under the GNU General Public License. (GPL 2.0 or greater).AUTHORSjoost witteveen<joostje@debian.org>Clint Adams<clint@debian.org>Timo SavolaMANUAL PAGEmostly by J.H.M. Dassen <jdassen@debian.org> Rather a lot mods/additions by joost and Clint.
fakeroot -rw-r--r-- ...