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
echoes
This account is currently not available.
before 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 with cd
. If you are a normal user and can't cd
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.