fakeroot(1)
โจ fakeroot(1) โจ
fakeroot is the Debian manual page for fakeroot ๐ (it lives in the Debian manual, no cap).
๐ธ NAME ๐ธ
fakeroot โ run a command in an environment faking root privileges for file manipulation ๐
๐ฆ SYNOPSIS ๐ฆ
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]
๐ DESCRIPTION ๐
okay so fakeroot runs a command in an environment where it appears to have root privileges for file manipulation โจ It's giving main character energy. This is so useful for letting regular users create archives (tar, ar, .deb etc.) with files in them that have root permissions and ownership ๐ซถ Without it, you'd need actual root privileges to make the files with the right permissions and ownership and then pack them up, or you'd have to build the archives directly without using the archiver. Bestie, that's a lot ๐ญ
fakeroot works by swapping out the file manipulation library functions (chmod(2), stat(2) etc.) for ones that fake the result the real functions would have given if the user had really been root ๐ง These wrapper functions live in a shared library, /usr/lib/*/libfakeroot-*.so or a similar location on your platform. The shared object gets loaded through the LD_PRELOAD mechanism of the dynamic loader. (See ld.so(8)) ๐ฅ
If you're planning to build packages with fakeroot, please try building the fakeroot package first ๐ The "debian/rules build" stage has a few tests (mostly checking for bugs in old fakeroot versions). If those tests fail (for example because you have certain libc5 programs on your system), other packages you build with fakeroot will quite likely fail too, but possibly in much more subtle ways ๐
Also, it's lowkey best not to build the binaries themselves under fakeroot ๐ Especially configure and friends don't like it when the system suddenly behaves differently from what they expect (or, they randomly unset some environment variables, some of which fakeroot needs).
๐ OPTIONS ๐
-l library,--lib libraryโ Pick an alternative wrapper library ๐--faked binaryโ Pick an alternative binary to use as faked ๐[--] commandโ Any command you want to run as fakeroot ๐ Use--if your command has other options that might confuse fakeroot's option parsing.-s save-fileโ Save the fakeroot environment to save-file on exit โจ You can restore it later with-i. Heads up though: this file will leak, and fakeroot will act in odd ways unless you leave the files touched inside the fakeroot alone when you're outside the environment ๐ Still, it can be super useful. For example, pair it with rsync(1) to back up and restore whole directory trees, complete with user, group and device information, without needing to be root ๐ฆ See/usr/share/doc/fakeroot/README.savingfor more details.-i load-fileโ Load a fakeroot environment previously saved with-sfrom load-file ๐ Heads up: this does not implicitly save the file, so use-sas well if you want that. Using the same file for both-iand-sin a single fakeroot invocation is safe ๐ซถ-u,--unknown-is-realโ Use the real ownership of files fakeroot didn't know about before, instead of pretending they're owned by root:root ๐-b fdโ Specify fd base (TCP mode only) ๐ง fd is the minimum file descriptor number to use for TCP connections. This can matter a lot for avoiding conflicts with the file descriptors used by the programs you run under fakeroot.-hโ Display help ๐-vโ Display version โญ
๐ EXAMPLES ๐
Here's an example session with fakeroot ๐ Notice that inside the fake root environment, file manipulation that normally needs root privileges succeeds, but it's not really happening ๐
$ whoami
joost
$ fakeroot /bin/bash
# whoami
root
# mknod hda3 b 3 1
# ls -ld hda3
brw-r--r-- 1 root root 3, 1 Jul 2 22:58 hda3
# chown joost:root hda3
# ls -ld hda3
brw-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
-rw-r--r-- 1 joost users 0 Jul 2 22:58 hda3
Only the effects that user joost could already do anyway actually happen for real ๐ญ
fakeroot was specifically written to let users create Debian GNU/Linux packages (in the deb(5) format) without giving them root privileges ๐
You can do this with commands like dpkg-buildpackage -rfakeroot or debuild -rfakeroot (actually, -rfakeroot is the default in debuild nowadays, so you don't need that argument) ๐
๐ SECURITY ASPECTS ๐
fakeroot 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 ๐ง
๐ ENVIRONMENT ๐
FAKEROOTKEYโ The key used to talk to the fakeroot daemon ๐ Any program started with the rightLD_PRELOADand theFAKEROOTKEYof a running daemon will automatically connect to that daemon and get the same "fake" view of the file system's permissions and ownerships (assuming the daemon and the connecting program were started by the same user) ๐LD_LIBRARY_PATHโ No description of its own here, it's covered right underLD_PRELOAD๐LD_PRELOADโ fakeroot works by wrapping system calls ๐ฅ This happens by settingLD_LIBRARY_PATH=/usr/lib/fakerootandLD_PRELOAD=libfakeroot.so.0. That library gets loaded before the system's C library, so most library functions get intercepted by it. If you need to set eitherLD_LIBRARY_PATHorLD_PRELOADfrom within a fakeroot environment, set it relative to the given paths, like this:LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/foo/bar/
โ ๏ธ LIMITATIONS โ ๏ธ
๐ Library versions ๐
Every 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 either of these:
touch foo
fakeroot
ls -al foo
or the other way around:
fakeroot
touch foo
ls -al foo
fakeroot has no way of knowing that in the first case the owner of foo really should be joost, while in the second case it should have been root ๐ญ For Debian packaging, defaulting all "unknown" files to uid=gid=0 is always OK ๐ซถ The real way around this would be to wrap open() and create(), but that creates other problems, as demonstrated by the libtricks package. That package wrapped many more functions and tried to do a lot more than fakeroot. It turned out that a minor libc upgrade (from one where the stat() function didn't use open() to one where stat() did, in some cases) caused unexplainable segfaults, because the libc6 stat() called the wrapped open(), which then called the libc6 stat(), and so on ๐ Fixing them wasn't all that easy, and once fixed, it was just a matter of time before another function started using open(), never mind trying to port it to a different operating system. So the author decided to keep the number of functions wrapped 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 confused by this (or if they don't, they may stress fakeroot so much that fakeroot itself gets confused) ๐ So it's advisable not to run "configure" from within fakeroot. Since configure should be called in the "debian/rules build" target, running dpkg-buildpackage -rfakeroot correctly takes care of this โจ
๐ BUGS ๐
It doesn't wrapopen(). This isn't bad by itself, but if a program doesopen("file", O_WRONLY, 000), writes to file "file", closes it, and then tries to open it again to read the file, that open fails, because the mode of the file will be 000 ๐ญ The bug is that if root does the same,open()will succeed, since file permissions aren't checked at all for root. The author chose not to wrapopen(), becauseopen()is used by many other functions in libc (including ones that are already wrapped), which would create loops (or possible future loops, when the implementation of various libc functions slightly changes).
๐ COPYING ๐
fakeroot is distributed under the GNU General Public License ๐ (GPL 2.0 or greater).
๐ฉโ๐ป AUTHORS ๐ฉโ๐ป
- joost witteveen โ <joostje@debian.org> ๐
- Clint Adams โ <clint@debian.org> ๐
- Timo Savola ๐
๐ MANUAL PAGE ๐
Mostly by J.H.M. Dassen <jdassen@debian.org>, with rather a lot of modsifications and additions by joost and Clint ๐
๐ SEE ALSO ๐
debuild(1),dpkg-buildpackage(1),faked(1),/usr/share/doc/fakeroot/DEBUG๐ฆ
Bye bestie, that's the whole fakeroot(1) page ๐ซถ Straight from the Debian Project, dated 2024-12-19 ๐
๐ฆ where this page comes from
- alpine 3.22: fakeroot-doc 1.37.1.1-r0 ยท GPL-3.0-or-later
- alpine 3.23: fakeroot-doc 1.37.1.2-r0 ยท GPL-3.0-or-later
- alpine 3.24: fakeroot-doc 1.37.2-r0 ยท GPL-3.0-or-later
- epel 10: fakeroot 1.37-1.el10_0 ยท GPL-3.0-or-later AND LicenseRef-Callaway-LGPLv2+ AND (GPL-1.0-or-later OR Artistic-1.0-Perl)
- epel 9: fakeroot 1.37-1.el9 ยท GPL-3.0-or-later AND LicenseRef-Callaway-LGPLv2+ AND (GPL-1.0-or-later OR Artistic-1.0-Perl)
- fedora 43: fakeroot 1.37.1-3.fc43 ยท GPL-3.0-or-later AND LicenseRef-Callaway-LGPLv2+ AND (GPL-1.0-or-later OR Artistic-1.0-Perl)
- fedora 44: fakeroot 1.37.1-4.fc44 ยท GPL-3.0-or-later AND LicenseRef-Callaway-LGPLv2+ AND (GPL-1.0-or-later OR Artistic-1.0-Perl)
- nixos 26.05: fakeroot 1.37.2
- nixpkgs unstable: fakeroot 1.38.1
- ubuntu questing: fakeroot 1.37.1.2-1
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms