JEXEC(8)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… JEXEC(8) πŸ’…

hey bestie, welcome to JEXEC(8) from the System Manager's Manual β€” this one is literally about running a command inside a jail that's already up and running. no cap, it's giving "let me just pop into this jail real quick" energy 🫢


✨ NAME ✨

jexec β€” execute a command inside an existing jail, periodt πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

jexec [-l] [-d working-directory] [-u username | -U username] jail
      [command ...]

🌸 DESCRIPTION 🌸

okay so 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. iconic, honestly ✨

the following options are available:


πŸŽ€ OPTIONS πŸŽ€

  • -d working-directory β€” the working directory for running commands inside the jail. the default is the jail root directory. very "set the vibe before you walk in" πŸ’…
  • -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 -u or -U), and absent the -d option, commands are run from that (possibly jailed) user's directory. clean slate, no baggage, we love to see it 🧚
  • -u username β€” the user name from host environment as whom the command should run. this is the default. host-side user, classic behavior πŸ‘‘
  • -U username β€” the user name from jailed environment as whom the command should run. jailed-side user, for when you're being extra specific πŸ”₯

🌈 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. lowkey efficient fr fr ⭐

# 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

πŸ’– SEE ALSO πŸ’–


⭐ HISTORY ⭐

the jexec utility was added in FreeBSD 5.1. vintage but still slaying πŸ’…


πŸ’€ BUGS πŸ’€

if the jail is not identified by jid there is a possible race in between the lookup of the jail and executing the command inside the jail. giving a jid has a similar race as another process can stop the jail and start another one after the user looked up the jid.

heads up bestie β€” race conditions are not the cute kind of drama 😭 keep this in mind.

mwah πŸ’‹ this page is brought to you by Debian, dated March 5, 2025, and lives in the System Manager's Manual β€” catch u later, bestie 🫢

πŸ“¦ where this page comes from