On a CentOS server where I'm logged via SSH as root, I do:
su otherusername
where 'otherusername' is the user name of another user, which exists.
It does nothing. After that, I'm still root. whoami returns root, any file I create belongs to root, that is, su just doesn't su.
However it does not give any error message. If I try to su with an invalid user name it does give an error message.
What am I missing??
Does otherusername have a valid shell in
/etc/passwd
?What
su
does is execute a process as another user. The process it chooses by default is whatever is in the last field in/etc/passwd
for the user in question. This is usually a shell such as/bin/sh
or/bin/bash
. When that process ends, you are dumped back into the original shell you started in, owned by root.As far as
su
is concerned, it has successfully switched to the correct user so no error message is required. It then hands control off to the configured shell by executing that. If this shell is something like/bin/false
, it will simply do what/bin/false
always does, which is exit with a 1 (false) status, dropping you back to the parent shell owned by the root user./bin/true
does the same thing but with a status of 0 (true).Other pseudo-shells may exhibit different behaviour. For instance,
/usr/sbin/nologin
echoesbefore exiting with 1.
You can change the configured shell for a user with
usermod -s /bin/bash otherusername
as the root user.You may see similar confusing behaviour around
sudo
if you use it withcd
. If you are a normal user and can'tcd
into a directory,sudo cd directory
will print no error message, will not change you to root and will not change your directory.The reason for this is that it starts a new shell as root, changes directory to the correct directory and then immediately exits, leaving you back in your original shell in your original directory.