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*5cf70549SJamie Gritton.Dd August 12, 2024 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 3570b75adfSXin LI.Op Fl u Ar username | Fl U Ar username 363bbdb8a7SJamie Gritton.Ar jail Op Ar command ... 37ebf5d9bcSMike Barcroft.Sh DESCRIPTION 38ebf5d9bcSMike BarcroftThe 39ebf5d9bcSMike Barcroft.Nm 40c16ad8ccSRuslan Ermilovutility executes 41ebf5d9bcSMike Barcroft.Ar command 4273d0971bSJamie Grittoninside the 4373d0971bSJamie Gritton.Ar jail 4473d0971bSJamie Grittonidentified by its jid or name. 453bbdb8a7SJamie GrittonIf 463bbdb8a7SJamie Gritton.Ar command 473bbdb8a7SJamie Grittonis not specified then the user's shell is used. 4870b75adfSXin LI.Pp 4970b75adfSXin LIThe following options are available: 5070b75adfSXin LI.Bl -tag -width indent 513bbdb8a7SJamie Gritton.It Fl l 523bbdb8a7SJamie GrittonExecute in a clean environment. 533bbdb8a7SJamie GrittonThe environment is discarded except for 543bbdb8a7SJamie Gritton.Ev HOME , SHELL , TERM , USER , 553bbdb8a7SJamie Grittonand anything from the login class capability database for the user. 567eb6a92eSGleb Popov.Ev PATH 577eb6a92eSGleb Popovis set to "/bin:/usr/bin". 58*5cf70549SJamie GrittonIf a user is specified (via 59*5cf70549SJamie Gritton.Fl u 60*5cf70549SJamie Grittonor 61*5cf70549SJamie Gritton.Fl U ) , 62*5cf70549SJamie Grittoncommands are run from that (possibly jailed) user's directory. 6370b75adfSXin LI.It Fl u Ar username 6470b75adfSXin LIThe user name from host environment as whom the 6570b75adfSXin LI.Ar command 6670b75adfSXin LIshould run. 674209de56SBenedict ReuschlingThis is the default. 6870b75adfSXin LI.It Fl U Ar username 6970b75adfSXin LIThe user name from jailed environment as whom the 7070b75adfSXin LI.Ar command 7170b75adfSXin LIshould run. 72bc84aa4bSRuslan Ermilov.El 7304c8bfc1SDanilo G. Baio.Sh EXAMPLES 7404c8bfc1SDanilo G. Baio.Ss Example 1 : Open a shell in a jail 7504c8bfc1SDanilo G. BaioThe following command specifies a jail by its name and utilizes the current 7604c8bfc1SDanilo G. Baiouser's shell: 7704c8bfc1SDanilo G. Baio.Pp 7804c8bfc1SDanilo G. Baio.Dl # jexec name 7904c8bfc1SDanilo G. Baio.Pp 8004c8bfc1SDanilo G. BaioIt is also possible to specify a jail by its jid: 8104c8bfc1SDanilo G. Baio.Pp 8204c8bfc1SDanilo G. Baio.Dl # jexec JID 8304c8bfc1SDanilo G. Baio.Ss Example 2 : Run a single command without opening a shell 8404c8bfc1SDanilo G. BaioThe following command runs 8504c8bfc1SDanilo G. Baio.Ql uname -a 8604c8bfc1SDanilo G. Baioin a jail called 8704c8bfc1SDanilo G. Baio.Dq name . 8804c8bfc1SDanilo G. BaioSince a command is specified explicitly, 8904c8bfc1SDanilo G. Baio.Nm 9004c8bfc1SDanilo G. Baiodoes not spawn an interactive shell. 9104c8bfc1SDanilo G. BaioInstead, 9204c8bfc1SDanilo G. Baio.Nm 9304c8bfc1SDanilo G. Baioexecutes the specified command directly. 9404c8bfc1SDanilo G. Baio.Pp 9504c8bfc1SDanilo G. Baio.Dl # jexec name uname -a 9604c8bfc1SDanilo G. Baio.Ss Example 3 : Open a shell in a jail with a clean environment 9704c8bfc1SDanilo G. BaioThe following command opens a 9804c8bfc1SDanilo G. Baio.Xr sh 1 9904c8bfc1SDanilo G. Baioshell in a jail with a clean environment: 10004c8bfc1SDanilo G. Baio.Pp 10104c8bfc1SDanilo G. Baio.Dl # jexec -l name sh 10204c8bfc1SDanilo G. Baio.Ss Example 4 : Open a shell in a jail with the login command 10304c8bfc1SDanilo G. BaioThe following command utilizes 10404c8bfc1SDanilo G. Baio.Xr login 1 10504c8bfc1SDanilo G. Baioto access the jail, submitting an audit record, and displaying the 10604c8bfc1SDanilo G. Baiouser's last login, system copyright, and 10704c8bfc1SDanilo G. Baio.Xr motd 5 10804c8bfc1SDanilo G. Baiomessage: 10904c8bfc1SDanilo G. Baio.Pp 11004c8bfc1SDanilo G. Baio.Dl # jexec -l name login -f root 111ebf5d9bcSMike Barcroft.Sh SEE ALSO 112ebf5d9bcSMike Barcroft.Xr jail_attach 2 , 113ebf5d9bcSMike Barcroft.Xr jail 8 , 114ebf5d9bcSMike Barcroft.Xr jls 8 115ebf5d9bcSMike Barcroft.Sh HISTORY 116ebf5d9bcSMike BarcroftThe 117ebf5d9bcSMike Barcroft.Nm 118ebf5d9bcSMike Barcroftutility was added in 119ebf5d9bcSMike Barcroft.Fx 5.1 . 120413628a7SBjoern A. Zeeb.Sh BUGS 121413628a7SBjoern A. ZeebIf the jail is not identified by 122413628a7SBjoern A. Zeeb.Ar jid 123413628a7SBjoern A. Zeebthere is a possible race in between the lookup of the jail 124413628a7SBjoern A. Zeeband executing the command inside the jail. 125413628a7SBjoern A. ZeebGiving a 126413628a7SBjoern A. Zeeb.Ar jid 127413628a7SBjoern A. Zeebhas a similar race as another process can stop the jail and 128413628a7SBjoern A. Zeebstart another one after the user looked up the 129413628a7SBjoern A. Zeeb.Ar jid . 130