0

I am trying to switch the user in my shell with su - [user], but the user seems to remain the old one:

# this works pretty well
bodo@bodo-work:~$ sudo -u mysql whoami
[sudo] password for bodo: 
mysql

# but not this
bodo@bodo-work:~$ whoami
bodo
bodo@bodo-work:~$ su - mysql
Password:

# still having 'bodo' as user seems to be wrong here 
bodo@bodo-work:~$ whoami
bodo # what?

Please note that there was no error message, like could not find home directory. What am I doing wrong here? The defined home directory of the user mysql belongs to it:

sudo ls -lah /var/lib/mysql
total 215M
drwx------  7 mysql mysql 4,0K Feb 10 14:30  .
# [...]
BairDev
  • 219
  • 1
  • 2
  • 9

1 Answers1

2

If you grep mysql /etc/passwd, I reckon you will find that the shell has been set to /sbin/nologin. Running sudo gets around that and will execute whoami as mysql. That is, the sbin/nologin does not run because is not regarded as a login shell.

When you run su - mysql, you get logged back out to bodo straight away since /sbin/nologin is being called and thus whoami is being run by bodo.

When I run the su, I do get the error This account is currently not available. back which I would have thought you would have seen.

Bib
  • 2,056
  • 1
  • 4
  • 10
  • This my well be! I was not aware of the mysql user being a no-login user, too. I've thought the **mysql user bodo** is a no-login user only. But where should I see `/sbin/nologin` since I cannot see this for `grep mysql /etc/passwd` (`mysql:x:127:134:MySQL Server,,,:/var/lib/mysql/:/bin/false`). Is it `/bin/false`? I also do not get your last point: where should I run `su` for getting this message? – BairDev Feb 10 '22 at 15:26
  • In your case, the shell has been set to `/bin/false` and that is always going to eject straight away, hence no `This account is cur...`. If you change the shell to `/sbin/nologin`, you will get the error message. – Bib Feb 10 '22 at 15:28