1ebf5d9bcSMike Barcroft.\" 2ebf5d9bcSMike Barcroft.\" Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3ebf5d9bcSMike Barcroft.\" All rights reserved. 4ebf5d9bcSMike Barcroft.\" 5ebf5d9bcSMike Barcroft.\" Redistribution and use in source and binary forms, with or without 6ebf5d9bcSMike Barcroft.\" modification, are permitted provided that the following conditions 7ebf5d9bcSMike Barcroft.\" are met: 8ebf5d9bcSMike Barcroft.\" 1. Redistributions of source code must retain the above copyright 9ebf5d9bcSMike Barcroft.\" notice, this list of conditions and the following disclaimer. 10ebf5d9bcSMike Barcroft.\" 2. Redistributions in binary form must reproduce the above copyright 11ebf5d9bcSMike Barcroft.\" notice, this list of conditions and the following disclaimer in the 12ebf5d9bcSMike Barcroft.\" documentation and/or other materials provided with the distribution. 13ebf5d9bcSMike Barcroft.\" 14ebf5d9bcSMike Barcroft.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ebf5d9bcSMike Barcroft.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ebf5d9bcSMike Barcroft.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ebf5d9bcSMike Barcroft.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18ebf5d9bcSMike Barcroft.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ebf5d9bcSMike Barcroft.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ebf5d9bcSMike Barcroft.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ebf5d9bcSMike Barcroft.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ebf5d9bcSMike Barcroft.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ebf5d9bcSMike Barcroft.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ebf5d9bcSMike Barcroft.\" SUCH DAMAGE. 25ebf5d9bcSMike Barcroft.\" 26*d56f3b05SJamie Gritton.Dd March 5, 2025 27ebf5d9bcSMike Barcroft.Dt JEXEC 8 28ebf5d9bcSMike Barcroft.Os 29ebf5d9bcSMike Barcroft.Sh NAME 30ebf5d9bcSMike Barcroft.Nm jexec 31c16ad8ccSRuslan Ermilov.Nd "execute a command inside an existing jail" 32ebf5d9bcSMike Barcroft.Sh SYNOPSIS 33ebf5d9bcSMike Barcroft.Nm 343bbdb8a7SJamie Gritton.Op Fl l 35*d56f3b05SJamie Gritton.Op Fl d Ar working-directory 3670b75adfSXin LI.Op Fl u Ar username | Fl U Ar username 373bbdb8a7SJamie Gritton.Ar jail Op Ar command ... 38ebf5d9bcSMike Barcroft.Sh DESCRIPTION 39ebf5d9bcSMike BarcroftThe 40ebf5d9bcSMike Barcroft.Nm 41c16ad8ccSRuslan Ermilovutility executes 42ebf5d9bcSMike Barcroft.Ar command 4373d0971bSJamie Grittoninside the 4473d0971bSJamie Gritton.Ar jail 4573d0971bSJamie Grittonidentified by its jid or name. 463bbdb8a7SJamie GrittonIf 473bbdb8a7SJamie Gritton.Ar command 483bbdb8a7SJamie Grittonis not specified then the user's shell is used. 4970b75adfSXin LI.Pp 5070b75adfSXin LIThe following options are available: 5170b75adfSXin LI.Bl -tag -width indent 52*d56f3b05SJamie Gritton.It Fl d Ar working-directory 53*d56f3b05SJamie GrittonThe working directory for running commands inside the jail. 54*d56f3b05SJamie GrittonThe default is the jail root directory. 553bbdb8a7SJamie Gritton.It Fl l 563bbdb8a7SJamie GrittonExecute in a clean environment. 573bbdb8a7SJamie GrittonThe environment is discarded except for 583bbdb8a7SJamie Gritton.Ev HOME , SHELL , TERM , USER , 593bbdb8a7SJamie Grittonand anything from the login class capability database for the user. 607eb6a92eSGleb Popov.Ev PATH 617eb6a92eSGleb Popovis set to "/bin:/usr/bin". 625cf70549SJamie GrittonIf a user is specified (via 635cf70549SJamie Gritton.Fl u 645cf70549SJamie Grittonor 655cf70549SJamie Gritton.Fl U ) , 66*d56f3b05SJamie Grittonand absent the 67*d56f3b05SJamie Gritton.Fl d 68*d56f3b05SJamie Grittonoption, commands are run from that (possibly jailed) user's directory. 6970b75adfSXin LI.It Fl u Ar username 7070b75adfSXin LIThe user name from host environment as whom the 7170b75adfSXin LI.Ar command 7270b75adfSXin LIshould run. 734209de56SBenedict ReuschlingThis is the default. 7470b75adfSXin LI.It Fl U Ar username 7570b75adfSXin LIThe user name from jailed environment as whom the 7670b75adfSXin LI.Ar command 7770b75adfSXin LIshould run. 78bc84aa4bSRuslan Ermilov.El 7904c8bfc1SDanilo G. Baio.Sh EXAMPLES 8004c8bfc1SDanilo G. Baio.Ss Example 1 : Open a shell in a jail 8104c8bfc1SDanilo G. BaioThe following command specifies a jail by its name and utilizes the current 8204c8bfc1SDanilo G. Baiouser's shell: 8304c8bfc1SDanilo G. Baio.Pp 8404c8bfc1SDanilo G. Baio.Dl # jexec name 8504c8bfc1SDanilo G. Baio.Pp 8604c8bfc1SDanilo G. BaioIt is also possible to specify a jail by its jid: 8704c8bfc1SDanilo G. Baio.Pp 8804c8bfc1SDanilo G. Baio.Dl # jexec JID 8904c8bfc1SDanilo G. Baio.Ss Example 2 : Run a single command without opening a shell 9004c8bfc1SDanilo G. BaioThe following command runs 9104c8bfc1SDanilo G. Baio.Ql uname -a 9204c8bfc1SDanilo G. Baioin a jail called 9304c8bfc1SDanilo G. Baio.Dq name . 9404c8bfc1SDanilo G. BaioSince a command is specified explicitly, 9504c8bfc1SDanilo G. Baio.Nm 9604c8bfc1SDanilo G. Baiodoes not spawn an interactive shell. 9704c8bfc1SDanilo G. BaioInstead, 9804c8bfc1SDanilo G. Baio.Nm 9904c8bfc1SDanilo G. Baioexecutes the specified command directly. 10004c8bfc1SDanilo G. Baio.Pp 10104c8bfc1SDanilo G. Baio.Dl # jexec name uname -a 10204c8bfc1SDanilo G. Baio.Ss Example 3 : Open a shell in a jail with a clean environment 10304c8bfc1SDanilo G. BaioThe following command opens a 10404c8bfc1SDanilo G. Baio.Xr sh 1 10504c8bfc1SDanilo G. Baioshell in a jail with a clean environment: 10604c8bfc1SDanilo G. Baio.Pp 10704c8bfc1SDanilo G. Baio.Dl # jexec -l name sh 10804c8bfc1SDanilo G. Baio.Ss Example 4 : Open a shell in a jail with the login command 10904c8bfc1SDanilo G. BaioThe following command utilizes 11004c8bfc1SDanilo G. Baio.Xr login 1 11104c8bfc1SDanilo G. Baioto access the jail, submitting an audit record, and displaying the 11204c8bfc1SDanilo G. Baiouser's last login, system copyright, and 11304c8bfc1SDanilo G. Baio.Xr motd 5 11404c8bfc1SDanilo G. Baiomessage: 11504c8bfc1SDanilo G. Baio.Pp 11604c8bfc1SDanilo G. Baio.Dl # jexec -l name login -f root 117ebf5d9bcSMike Barcroft.Sh SEE ALSO 118ebf5d9bcSMike Barcroft.Xr jail_attach 2 , 119ebf5d9bcSMike Barcroft.Xr jail 8 , 120ebf5d9bcSMike Barcroft.Xr jls 8 121ebf5d9bcSMike Barcroft.Sh HISTORY 122ebf5d9bcSMike BarcroftThe 123ebf5d9bcSMike Barcroft.Nm 124ebf5d9bcSMike Barcroftutility was added in 125ebf5d9bcSMike Barcroft.Fx 5.1 . 126413628a7SBjoern A. Zeeb.Sh BUGS 127413628a7SBjoern A. ZeebIf the jail is not identified by 128413628a7SBjoern A. Zeeb.Ar jid 129413628a7SBjoern A. Zeebthere is a possible race in between the lookup of the jail 130413628a7SBjoern A. Zeeband executing the command inside the jail. 131413628a7SBjoern A. ZeebGiving a 132413628a7SBjoern A. Zeeb.Ar jid 133413628a7SBjoern A. Zeebhas a similar race as another process can stop the jail and 134413628a7SBjoern A. Zeebstart another one after the user looked up the 135413628a7SBjoern A. Zeeb.Ar jid . 136