1dea673e9SRodney W. Grimes.\" Copyright (c) 1988, 1991, 1993 2dea673e9SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 3dea673e9SRodney W. Grimes.\" 4dea673e9SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 5dea673e9SRodney W. Grimes.\" modification, are permitted provided that the following conditions 6dea673e9SRodney W. Grimes.\" are met: 7dea673e9SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 8dea673e9SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 9dea673e9SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 10dea673e9SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 11dea673e9SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 13dea673e9SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 14dea673e9SRodney W. Grimes.\" without specific prior written permission. 15dea673e9SRodney W. Grimes.\" 16dea673e9SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17dea673e9SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18dea673e9SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19dea673e9SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20dea673e9SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21dea673e9SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22dea673e9SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23dea673e9SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24dea673e9SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25dea673e9SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26dea673e9SRodney W. Grimes.\" SUCH DAMAGE. 27dea673e9SRodney W. Grimes.\" 28*a40cf417SEdward Tomasz Napierala.Dd July 20, 2021 29dea673e9SRodney W. Grimes.Dt CHROOT 8 30a4c37c81SRuslan Ermilov.Os 31dea673e9SRodney W. Grimes.Sh NAME 32dea673e9SRodney W. Grimes.Nm chroot 33dea673e9SRodney W. Grimes.Nd change root directory 34dea673e9SRodney W. Grimes.Sh SYNOPSIS 35e97407b4SRuslan Ermilov.Nm 36f0181db7SMateusz Piotrowski.Op Fl G Ar group Ns Op Cm \&, Ns Ar group ... 374fb3a306SMike Makonnen.Op Fl g Ar group 38f0181db7SMateusz Piotrowski.Op Fl u Ar user 39*a40cf417SEdward Tomasz Napierala.Op Fl n 40dea673e9SRodney W. Grimes.Ar newroot 41f0181db7SMateusz Piotrowski.Op Ar command Op Ar arg ... 42dea673e9SRodney W. Grimes.Sh DESCRIPTION 43dea673e9SRodney W. GrimesThe 4414b374a5SPhilippe Charnier.Nm 45490d5836SPhilippe Charnierutility changes its current and root directories to the supplied directory 46dea673e9SRodney W. Grimes.Ar newroot 47c5001dbdSRuslan Ermilovand then exec's 48f0181db7SMateusz Piotrowski.Ar command 49f0181db7SMateusz Piotrowskiwith provided arguments, if supplied, 504fb3a306SMike Makonnenor an interactive copy of the user's login shell. 514fb3a306SMike Makonnen.Pp 52f0181db7SMateusz PiotrowskiThe options are as follows: 53f0181db7SMateusz Piotrowski.Bl -tag -width "-G group[,group ...]" 54f0181db7SMateusz Piotrowski.It Fl G Ar group Ns Op Cm \&, Ns Ar group ... 55f0181db7SMateusz PiotrowskiRun the command with the permissions of the specified groups. 56f0181db7SMateusz Piotrowski.It Fl g Ar group 57f0181db7SMateusz PiotrowskiRun the command with the permissions of the specified 58f0181db7SMateusz Piotrowski.Ar group . 59f0181db7SMateusz Piotrowski.It Fl u Ar user 60f0181db7SMateusz PiotrowskiRun the command as the 61f0181db7SMateusz Piotrowski.Ar user . 62*a40cf417SEdward Tomasz Napierala.It Fl n 63*a40cf417SEdward Tomasz NapieralaUse the 64*a40cf417SEdward Tomasz Napierala.Dv PROC_NO_NEW_PRIVS_CTL 65*a40cf417SEdward Tomasz Napierala.Xr procctl 2 66*a40cf417SEdward Tomasz Napieralacommand before chrooting, effectively disabling SUID/SGID bits 67*a40cf417SEdward Tomasz Napieralafor the calling process and its descendants. 68*a40cf417SEdward Tomasz NapieralaIf 69*a40cf417SEdward Tomasz Napierala.Dv security.bsd.unprivileged_chroot 70*a40cf417SEdward Tomasz Napieralasysctl is set to 1, it will make it possible to chroot without 71*a40cf417SEdward Tomasz Napieralasuperuser privileges. 72f0181db7SMateusz Piotrowski.El 73dea673e9SRodney W. Grimes.Sh ENVIRONMENT 74dea673e9SRodney W. GrimesThe following environment variable is referenced by 75e97407b4SRuslan Ermilov.Nm : 76f0181db7SMateusz Piotrowski.Bl -tag -width "SHELL" 77dea673e9SRodney W. Grimes.It Ev SHELL 78dea673e9SRodney W. GrimesIf set, 79dea673e9SRodney W. Grimesthe string specified by 80dea673e9SRodney W. Grimes.Ev SHELL 81dea673e9SRodney W. Grimesis interpreted as the name of 82dea673e9SRodney W. Grimesthe shell to exec. 83dea673e9SRodney W. GrimesIf the variable 84dea673e9SRodney W. Grimes.Ev SHELL 85dea673e9SRodney W. Grimesis not set, 86dea673e9SRodney W. Grimes.Pa /bin/sh 87dea673e9SRodney W. Grimesis used. 88dea673e9SRodney W. Grimes.El 89f0181db7SMateusz Piotrowski.Sh EXAMPLES 90f0181db7SMateusz Piotrowski.Bl -tag -width 0n 91f0181db7SMateusz Piotrowski.It Sy Example 1\&: No Chrooting into a New Root Directory 92f0181db7SMateusz Piotrowski.Pp 93f0181db7SMateusz PiotrowskiThe following command opens the 94f0181db7SMateusz Piotrowski.Xr csh 1 95f0181db7SMateusz Piotrowskishell after chrooting to the standard root directory. 96f0181db7SMateusz Piotrowski.Bd -literal -offset 2n 97f0181db7SMateusz Piotrowski.Li # Ic chroot / /bin/csh 98f0181db7SMateusz Piotrowski.Ed 99f0181db7SMateusz Piotrowski.It Sy Example 2\&: No Execution of a Command with a Changed Root Directory 100f0181db7SMateusz Piotrowski.Pp 101f0181db7SMateusz PiotrowskiThe following command changes a root directory with 102f0181db7SMateusz Piotrowski.Nm 103f0181db7SMateusz Piotrowskiand then runs 104f0181db7SMateusz Piotrowski.Xr ls 1 105f0181db7SMateusz Piotrowskito list the contents of 106f0181db7SMateusz Piotrowski.Pa /sbin . 107f0181db7SMateusz Piotrowski.Bd -literal -offset 2n 108f0181db7SMateusz Piotrowski.Li # Ic chroot /tmp/testroot ls /sbin 109f0181db7SMateusz Piotrowski.Ed 110f0181db7SMateusz Piotrowski.El 111dea673e9SRodney W. Grimes.Sh SEE ALSO 112dea673e9SRodney W. Grimes.Xr chdir 2 , 113dea673e9SRodney W. Grimes.Xr chroot 2 , 1144fb3a306SMike Makonnen.Xr setgid 2 , 1154fb3a306SMike Makonnen.Xr setgroups 2 , 1164fb3a306SMike Makonnen.Xr setuid 2 , 1174fb3a306SMike Makonnen.Xr getgrnam 3 , 118a2e78261SMike Pritchard.Xr environ 7 , 119a2e78261SMike Pritchard.Xr jail 8 120dea673e9SRodney W. Grimes.Sh HISTORY 121dea673e9SRodney W. GrimesThe 12214b374a5SPhilippe Charnier.Nm 123c0b0bcf4SMike Pritchardutility first appeared in 124643d5ca3SWarner Losh.At III 125643d5ca3SWarner Loshand 126643d5ca3SWarner Losh.Bx 4.3 Reno . 127