Would su, sudo or ssh honor /sbin/nologin?
September 15, 2017 | Linux SecurityIf a user’s login shell is /sbin/nologin
, would su, sudo or ssh honor it? Let’s find it out.
On a typical CentOS 7 installation, the login shell of user adm is /sbin/nologin
(see /etc/passwd
):
su
su apparently honors entries in /etc/passwd
. If we try to use su to run a command with adm, it will fail, as expected.
However, we can override the login shell in the password database, by supplying a shell (e.g., -s /bin/bash
) in the CLI.
If we give adm a password, we can even su to adm from an unprivileged user. For example:
sudo
By contrast, sudo doesn’t honor /sbin/nologin
in /etc/passwd
:
However, if we use the -i
option to simulate initial login, sudo will run the shell specified by the password database entry of the target user as a login shell, in this case, /sbin/nologin
:
ssh
As expected, ssh does honor /sbin/nologin
in the password database. If we change user dong’s login shell to /sbin/nologin
, ssh will fail: