2

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 well
  • sudo chroot --userspec=test1 chroot_dir/ /bin/bash --login says chroot: 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, where user 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.

5

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 and bin/bash in the chroot;
  • lib and any libraries therein used by bash, 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.