chroot: failed to run command ‘/bin/bash’: Permission denied
With chroot (and no user namespaces, which is the case here), the directories and files necessary to run the command you give to chroot need to be accessible to the user you specify. This includes:
- the chroot’s root;
binandbin/bashin the chroot;liband any libraries therein used bybash, if any (ldd bin/bashwill tell you what they are);- when
bashgets going,home/testand any startup scripts (.bashrcetc. if necessary).
Running chmod -R 777 obviously fixes all this; you can use more restrictive permissions, as long as user id 1001 can read and execute the appropriate files. chmod -R 755 bin lib and chmod 755 . would allow bash to start.
Related videos on Youtube
karlosss
Updated on September 18, 2022Comments
-
karlosss 3 monthsI am trying to do a chroot as a certain user. For one user it works, for other users it does not, and I have no idea what is going on.
My
/etc/passwdin the chroot directory looks like this (relevant part):test0:x:1000:1000:test0:/home/test:/bin/bash test1:x:1001:1001:test1:/home/test:/bin/bashsudo chroot --userspec=test0 chroot_dir/ /bin/bash --loginworks wellsudo chroot --userspec=test1 chroot_dir/ /bin/bash --loginsayschroot: failed to run command ‘/bin/bash’: Permission denied- details of
/bin/bashin chroot:-rwxr-xr-x 1 user user 455188 Sep 19 08:58, whereuseris my username in the system.
Any ideas why user
test1does not work? If you need any more information, just please ask, I will put them in. Thanks a lot in advance.