Gentoo – bash: su: command not found – missing su flag

Upgrading multiple packages may lead to interesting results especially if the queue has not finished yet or the fails with an error! Apparently, there are two main ways to have the basic command SU in the system installed:

  1. sys-apps/shadow
  2. sys-apps/util-linux

At some point, the default inclusion of su flags in the above packages had changed from sys-apps/shadow to sys-apps/util-linux, which may lead to the following interesting error:

user@srv ~ $ su
bash: /bin/su: command not found

Just check, which of the above packages includes the su flag and re-emerge it. At present, sys-apps/util-linux includes it by default and it should work without any explicit activation in portage package use (i.e. /etc/portage/package.use/mybase or /etc/portage/make.conf, for example) file.

At the moment, here is the default:

user@srv ~ # emerge -vp shadow util-linux

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] sys-apps/shadow-4.11.1:0/4::gentoo  USE="acl (audit) nls pam (selinux) (split-usr) xattr -bcrypt -cracklib -skey -su" 0 KiB
[ebuild   R    ] sys-apps/util-linux-2.37.2-r3::gentoo  USE="(audit) (caps) cramfs hardlink logger ncurses nls pam python readline (selinux) (split-usr) su suid udev (unicode) -build -cryptsetup -fdformat -kill -magic (-rtas) -slang -static-libs -systemd -test -tty-helpers" ABI_X86="32 (64) (-x32)" PYTHON_TARGETS="python3_8 -python3_9 -python3_10" 0 KiB

Total: 2 packages (2 reinstalls), Size of downloads: 0 KiB

su flag is missing in sys-apps/shadow and is included in sys-apps/util-linux

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…