chroot(8)

chroot8

Change root directory

Usage

chroot [-G group [,group ...]] [-g group] [-u user] 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 permissions of the specified groups.

-g group

Run the command with the permissions of the specified group.

-u user

Run the command as the user.

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

163 releases since Mac OS X 10.0; the text changed 2 times.

  1. 10.0–10.3.3
  2. 10.3.4–12.2
  3. 12.3–26.5

-g since macOS 12.3; -u since macOS 12.3.

History

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

From shell_cmds 329 in macOS 26.5. Parsed by carta from the page's mdoc source.