$linuxjunkies
>

fakeroot(1)

Run a command in an environment where file ownership and permissions appear to be modified without actual root privileges.

UbuntuDebianFedoraArch

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

FlagWhat it does
-l LIBRARYSpecify alternate libc wrapper library to load (advanced usage)
-f CONFIGRead configuration from file instead of default
-i STATEFILELoad fake root state from a previously saved file
-o STATEFILESave fake root state to file after command execution
-s STATEFILELoad state before and save after (shorthand for -i and -o)
-uUse underlying real ownership instead of faked attributes
-b BLOCKDEVICETreat device as a block device with fake attributes
--unknown-is-realTreat 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.deb

Change ownership of files to root and save the fake state for later use

fakeroot -s statefile.dat chown -R root:root /tmp/builddir

Load previous fake state, modify permissions, and update the saved state

fakeroot -i statefile.dat -o statefile.dat chmod -R 755 /tmp/builddir

Create 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/builddir

Show that even within fakeroot, your real UID is unchanged; only file operations are faked

fakeroot env id

Related commands