jexec8
Execute a command inside an existing jail
Usage
jexec [-l]
[-d
working-directory]
[[-e
name=value] ...]
[{-u
username | -U
username}]
jail
[command ...]
Overview
The jexec utility executes command inside the jail identified by its jid or name. If command is not specified then the user's shell is used.
The following options are available:
-
-d working-directory -
The working directory for running commands inside the jail. The default is the jail root directory.
-
-l -
Execute in a clean environment. The environment is discarded except for HOME, SHELL, TERM, USER, and anything from the login class capability database for the user. PATH is set to "/bin:/usr/bin". If a user is specified (via
-uor-U), and absent the-doption, commands are run from that (possibly jailed) user's directory. -
-e name=value -
Set environment variables.
This parameter allows arbitrary environment variables that are available to the process to be executed inside of the jail, overwriting any previously defined environment variables, such as those specified by the
-lparameter.This option can be set multiple times.
-
-u username -
The user name from host environment as whom the command should run. This is the default.
-
-U username -
The user name from jailed environment as whom the command should run.
Examples
Example 1 : Open a shell in a jail
The following command specifies a jail by its name and utilizes the current user's shell:
# jexec name
It is also possible to specify a jail by its jid:
# jexec JID
Example 2 : Run a single command without opening a shell
The following command runs ‘uname -a’ in a jail called “name”. Since a command is specified explicitly, jexec does not spawn an interactive shell. Instead, jexec executes the specified command directly.
# jexec name uname -a
Example 3 : Open a shell in a jail with a clean environment
The following command opens a sh(1) shell in a jail with a clean environment:
# jexec -l name sh
Example 4 : Open a shell in a jail with the login command
The following command utilizes login(1) to access the jail, submitting an audit record, and displaying the user's last login, system copyright, and motd(5) message:
# jexec -l name login -f root
Releases
55 releases since FreeBSD 5.1-RELEASE; the text changed 39 times.
- 5.1
- 5.2–6.1
- 6.2–6.3
- 6.4
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 9.0
- 9.1
- 9.2
- 9.3
- 10.0
- 10.1
- 10.2
- 10.3
- 10.4
- 11.0
- 11.1
- 11.2
- 11.3
- 11.4
- 12.0
- 12.1
- 12.2
- 12.3
- 12.4
- 13.0–13.2
- 13.3–13.5
- 14.0
- 14.1
- 14.2
- 14.3–15.1
- 16.0
-U since FreeBSD 6.2-RELEASE;
-d since FreeBSD 14.3-RELEASE;
-e since FreeBSD 16.0-CURRENT (2026-10-27);
-l since FreeBSD 10.3-RELEASE;
-u since FreeBSD 6.2-RELEASE.
-n until FreeBSD 7.4-RELEASE.