su to user with no shell

Most users in our linux/unix system have no ability to login, because the shell is /sbin/nologin (or even /bin/false). But sometimes we need to execute a command or to get in the shell under those users and when we try to switch the user to let’s sat nginx or apache or nagios we get an error:

[root@srv ~]# su nginx
This account is currently not available.
[root@srv ~]# su apache
This account is currently not available.
[root@srv ~]# su nagios
This account is currently not available.
[root@srv ~]# su nrpe
This account is currently not available.

But still we need to run a command or commands from that user! So we can do it with instructing the su command which shell to execute for us not taking into account the one in /etc/passwd:

su nagios -s /bin/bash

And now we are user “nagios”:

[root@srv ~]# su nagios -s /bin/bash
bash-4.2$ whoami
nagios

Go and execute commands to see why something is not working under you nagios user…

Leave a Reply

Your email address will not be published.