Bash – Why the ‘who’ Command Does Not Show ‘root’ as Logged In User

bashrootsusudo

When I log in as root from gnome-terminal using the command:

sudo su

it logs me in as the root user.

Isn't this switching a user considered as a log in?

Also, which command can show me all the "switching" I have done?

Best Answer

First, let's take a look at man who:

Print information about users who are currently logged in.

As you said,

sudo su it logs me as root user

So, it's about you, not about root.

And you are right. This is from man sudo:

sudo allows a permitted user to execute a command as the superuser or
another user, as specified by the security policy.

So, again, when you run sudo su command, in fact you (not root) are executing su command as the superuser.

If you want to became root, first you must to enable root account. See here how to do this:

After this you can login with root in tty1-6, via ssh, in GUI at the login screen, etc.

In Ubuntu it seems that there is an alternative to get root logged without to enable his account. The following command will do this:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gnome-terminal

This will open a root terminal:

root terminal

Related to the second question, I give you a hint: look in /var/log directory for files like auth.log.*.