restricted shell (no cd out of home directory)

restricted shell (no cd out of home directory)

Post by David Boyc » Tue, 10 Feb 1998 04:00:00

> Does a shell exist that does the following???

> I need a shell which will allow 'cd' while inside the user's home
> directory but will not allow a cd (or chroot) outside of their directory.

Well, with the ksh (and presumably others) you could try something like

% trap '[[ $PWD = $HOME* ]] || cd -' DEBUG

Which would cd back to the previous directory before executing any
commands if the current directory is outside of the home dir.  But of
course that wouldn't stop a sophisticated user from removing the trap.
It's possible you could find a way to cause the trap to be set as part
of evaluating PS1, in which case you could then make PS1 read only
("readonly PS1") and prevent the user from unsetting the trap that way,
but I haven't tried it

-David Boyce