I think if you add
if grep "\\<${USER}\\>" /etc/jailbirds > /dev/null
then
echo I am not a crook
else
exec chroot $CWD
endif
to the end of your /etc/profile
you might get what you are asking for, but it may have some side effects I'm not aware of (taking over the shell running /etc/profile
might cause problems). In this case you would need to create a file /etc/jailbirds
which was a list of the users you wanted to chroot for. You'll also need to make sure that this file exists and decide what to do in the case of errors accessing it to make sure that other users (especially root) don't get locked up by chroot
Additionally, doing this is going to be difficult. The user will be unable to access /proc
which will make many shell utilities (such as ps
, top
, and many others) not work. The user will also not be able to access /dev/null
, which will break lots of stuff.
The user will also not be able to access /dev/tty
which will break less
and more
when used with standard input. The user's applications will inherit the stdin, stdout, and stderr open file descriptors from before the chroot, but less opens /dev/tty so that it can get keystrokes from the user to deal with having stdin redirected from a pipe.
You will also not be able to access any programs or shared libraries or many files that live under /etc (such as /etc/protocols ) that many programs use.
All of these are things you can work around, but you will end up needing to do a lot more work to make the users' environment usable than I think you have considered.
If you do try my suggestion I suggest you be very careful. It would be easy to get it wrong and mess things up bad. I have not tested this, by the way.
/etc/security/chroot.conf
i have add lines like:user1 /home/user1
, and/home/user1
will be the root for user1, right? Should i restart something to make the modifications at/etc/security/chroot.conf
to take effect?