I need to (temporarily) jail a non-privileged user.
I tried something like:
sudo chroot --userspec=mcon:users /wherever/chroottarget /bin/bash -i
This almost works, but it doesn't set env vars (while "sudo" does!), so I get the error:
bash: /root/.bashrc: Permission denied
How can I solve the problem? (NOTE: the above command should be inside a bash script)
UPDATE: I found a (rather convolute) way to do what I need:
sudo bash -c "HOME=<jailed home> chroot --userspec=<user>:<group> <chroottarget> /bin/bash -i"
Ideally I should read HOME from jailed /etc/passwd, along with all other environment (take them from jailed /etc/profile), this "solution" will keep intact all variables in the caller environment.
Is there a better way?