chroot(8)

chroot8

Change root directory

Usage

chroot [-G group [,group ...]] [-g group] [-u user] [-n] newroot [command [arg ...]]

Overview

The chroot utility changes its current and root directories to the supplied directory newroot and then exec's command with provided arguments, if supplied, or an interactive copy of the user's login shell.

The options are as follows:

-G group[,group ...]

Run the command with the specified groups as supplementary groups.

-g group

Run the command with the specified group as the real, effective and saved groups.

-u user

Run the command with the specified user as the real, effective and saved users.

-n

Use the PROC_NO_NEW_PRIVS_CTL procctl(2) command before chrooting, effectively disabling SUID/SGID bits for the calling process and its descendants. If security.bsd.unprivileged_chroot sysctl is set to 1, it will make it possible to chroot without superuser privileges.

Environment

The following environment variable is referenced by chroot:

SHELL

If set, the string specified by SHELL is interpreted as the name of the shell to exec. If the variable SHELL is not set, /bin/sh is used.

Examples

Example 1: Chrooting into a New Root Directory

The following command opens the csh(1) shell after chrooting to the standard root directory.

# chroot / /bin/csh
Example 2: Execution of a Command with a Changed Root Directory

The following command changes a root directory with chroot and then runs ls(1) to list the contents of /sbin.

# chroot /tmp/testroot ls /sbin

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 48 times.

  1. 2.0.5–2.1.7.1
  2. 2.2.2
  3. 2.2.5–3.5.1
  4. 4.0–4.2
  5. 4.3
  6. 4.4
  7. 4.5–4.7
  8. 4.8
  9. 4.9–4.11
  10. 5.0–5.1
  11. 5.2–5.2.1
  12. 5.3–6.3
  13. 6.4
  14. 7.0
  15. 7.1
  16. 7.2
  17. 7.3
  18. 7.4
  19. 8.0
  20. 8.1
  21. 8.2
  22. 8.3
  23. 8.4
  24. 9.0
  25. 9.1
  26. 9.2
  27. 9.3
  28. 10.0
  29. 10.1
  30. 10.2
  31. 10.3
  32. 10.4
  33. 11.0
  34. 11.1
  35. 11.2
  36. 11.3
  37. 11.4
  38. 12.0
  39. 12.1
  40. 12.2
  41. 12.3
  42. 12.4
  43. 13.0
  44. 13.1–13.2
  45. 13.3–14.3
  46. 14.4
  47. 14.5
  48. 15.0
  49. 15.1–16.0

-g since FreeBSD 13.0-RELEASE; -n since FreeBSD 13.1-RELEASE; -u since FreeBSD 13.0-RELEASE.

History

The chroot utility first appeared in AT&T System III UNIX and 4.3BSD-Reno.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.