I have browser shell leash and I'm executing shell commands in php and returing them to the browser and I just discovered chroot command and I want to run for example ls
on root directory on changed root, In fact I need to run bash -c "ls /"
. I've try this (I've try without sudo but it was not working):
sudo chroot ~/projects/jcubic/leash ls
but got error:
chroot: failed to run command ‘ls’: No such file or directory
do I use this command properly? Is it possible to run ls on different root directory?
when I've try to run chroot without sudo I've got this error:
chroot: cannot change root directory to '/home/kuba/projects/jcubic/leash': Operation not permitted
Best Answer
To run any command inside the chroot, you need to have this program available in the chroot (since it can not use the program installed in the
/
of filesystem.The simplest way is to copy the
/usr/bin/ls
from to/home/kuba/projects/jcubic/leash/usr/bin/
(you will also need the dependent shared libraries:ldd /usr/bin/ls
).