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;
bin
andbin/bash
in the chroot;lib
and any libraries therein used bybash
, if any (ldd bin/bash
will tell you what they are);- when
bash
gets going,home/test
and any startup scripts (.bashrc
etc. 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 over 1 year
I 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/passwd
in 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/bash
sudo chroot --userspec=test0 chroot_dir/ /bin/bash --login
works wellsudo chroot --userspec=test1 chroot_dir/ /bin/bash --login
sayschroot: failed to run command ‘/bin/bash’: Permission denied
- details of
/bin/bash
in chroot:-rwxr-xr-x 1 user user 455188 Sep 19 08:58
, whereuser
is my username in the system.
Any ideas why user
test1
does not work? If you need any more information, just please ask, I will put them in. Thanks a lot in advance.