I want to create a new user with a restricted shell so I :
ln -s bash rbash # create a symbolic link to bash with a name "rbash"
useradd -s /bin/rbash student # add a new user with a shell pointing to that symlink I've created
passwd student # create a password
su - student # Login as a user
However afterwards I can cd into wherever I want. It looks like a restricted shell doesn't work. Why ?
In
man bash
, the restricted shell is mentioned as follows:However, it looks like the version of
su
in Ubuntu 18.04 replaces the name of the shell withsu
; so when bash looks at itsargv[0]
it seessu
(or-su
in the case thatsu
was invoked with one of the-
,-l
or--login
options) instead ofrbash
(or-rbash
).You can actually change this behavior by editing the
/etc/login.defs
file and commenting out theSU_NAME
setting:Whether this is a good idea, or may have other unintended consequences, I can't say. Note that newer versions of Ubuntu likely use a different implementation of
/bin/su
(from theutil-linux
package) which may not exhibit the same behavior.