LinuxCommandLibrary

fakeroot

Simulate root privileges for package building

TLDR

Start the default shell as fakeroot

$ fakeroot
copy

Run a command as fakeroot
$ fakeroot -- [command] [command_arguments]
copy

Run a command as fakeroot and [s]ave the environment to a file on exit
$ fakeroot -s [path/to/file] -- [command] [command_arguments]
copy

Load a fakeroot environment and run a command as fakeroot
$ fakeroot -i [path/to/file] -- [command] [command_arguments]
copy

Run a command keeping the real ownership of files instead of pretending they are owned by root
$ fakeroot [[-u|--unknown-is-real]] -- [command] [command_arguments]
copy

Display help
$ fakeroot [[-h|--help]]
copy

SYNOPSIS

fakeroot [options] program [arguments ...]

PARAMETERS

-h, --help
    Display help message and exit

-v, --version
    Print version information and exit

-u, --user
    Run in user mode (no root simulation)

-i FILE, --load-state=FILE
    Load fakeroot state from specified file

-l FILE, --save-state=FILE
    Save fakeroot state to specified file

-s FILE
    Synonym for --save-state=FILE

--clean
    Clean environment variables set by fakeroot

--single-session
    Enable single fakeroot session mode

--faked
    Use faked backend instead of libfakeroot

--fd-fd
    Use fd-fd communication method

--faked-nopwnam
    Disable getpwnam in faked backend

--faked-no-putenv
    Disable putenv in faked backend

--norun-update-motd
    Skip running update-motd script

DESCRIPTION

Fakeroot is a tool that allows users to run commands in an environment mimicking root privileges, without requiring actual superuser rights. It achieves this by intercepting system calls related to file ownership, permissions, and capabilities via LD_PRELOAD (using libfakeroot) or a helper daemon (faked). This is particularly useful for tasks like creating Debian packages, tar archives, or RPMs where files need root-owned attributes, but building as non-root is preferred for security.

Key use cases include dpkg-buildpackage, make install DESTDIR=..., or scripting package creation. It tracks changes to file metadata in memory or a state file, applying them virtually. However, it doesn't handle all operations perfectly—kernel-level actions like device access or mounts remain restricted.

Fakeroot enhances portability and safety in build environments, widely used in distributions like Debian, Ubuntu, and Fedora.

CAVEATS

Cannot simulate kernel-level operations like mounts, mknod for devices, or ptrace; some syscalls may leak real user info; not suitable for interactive shells or unhandled commands; potential state inconsistencies across sessions.

COMMON USAGE

fakeroot make install to build with fake ownership
fakeroot tar czf pkg.tar.gz dir/ for root-owned archives

BACKENDS

libfakeroot: LD_PRELOAD syscall interception (default)
faked: User-space daemon with /proc monitoring

HISTORY

Developed by Joost Witteveen in 1997 for Debian packaging; maintained as part of devscripts; libfakeroot introduced for better performance; supports multiple backends; integrated into major distros for reproducible builds.

SEE ALSO

fakechroot(1), sudo(8), chroot(8), pbuilder(1)

Copied to clipboard