fakeroot(1)
Run a command in an environment where file ownership and permissions appear to be modified without actual root privileges.
Synopsis
fakeroot [-l LIBRARY] [-f CONFIG] [-i INPUT] [-o OUTPUT] [-u] [-s STATEFILE] [--] [COMMAND]Description
fakeroot runs a command in a fake root environment where the user appears to have root privileges for file operations. It intercepts system calls related to file ownership, permissions, and special files, making them appear modified without requiring actual root access.
This is particularly useful for building packages (RPM, DEB) where you need to create files owned by root or with special permissions, or for testing code that checks ownership without requiring real root privileges.
fakeroot maintains a database of fake file attributes and can save/restore this state between invocations, allowing you to build complex directory structures across multiple command executions.
Common options
| Flag | What it does |
|---|---|
-l LIBRARY | Specify alternate libc wrapper library to load (advanced usage) |
-f CONFIG | Read configuration from file instead of default |
-i STATEFILE | Load fake root state from a previously saved file |
-o STATEFILE | Save fake root state to file after command execution |
-s STATEFILE | Load state before and save after (shorthand for -i and -o) |
-u | Use underlying real ownership instead of faked attributes |
-b BLOCKDEVICE | Treat device as a block device with fake attributes |
--unknown-is-real | Treat unknown files as real rather than faked |
Examples
Build a Debian package with proper root ownership without needing actual root privileges
fakeroot dpkg-deb -b mypackage mypackage.debChange ownership of files to root and save the fake state for later use
fakeroot -s statefile.dat chown -R root:root /tmp/builddirLoad previous fake state, modify permissions, and update the saved state
fakeroot -i statefile.dat -o statefile.dat chmod -R 755 /tmp/builddirCreate a file, change its ownership to root, and verify the fake ownership appears in listing
fakeroot sh -c 'touch file.txt && chown root:root file.txt && ls -l file.txt'Create a tarball where all files appear to be owned by root, using -- to separate options
fakeroot -- tar czf package.tar.gz /tmp/builddirShow that even within fakeroot, your real UID is unchanged; only file operations are faked
fakeroot env id