1

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?

0

You need to change the environment variable $HOME to match the user's.

export HOME=/home/user-name

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.