3

I was trying to perform some root-level action on my Ubuntu server. When I switched to the root user, I found that the username is different. I usually switch to the root user with the following command:

sudo su - 

But the prompt was showing as a different user: webadm-dev. I checked on the /etc/shadow if anyone tried to add some user and I found nothing. I tried to switch to the root user (after switching back to the logged in user) with the following:

sudo su - root

It got changed. I exited back and tried to run my usual command again:

sudo su -

and the username is changed back to the root user. I am not able to understand the behavior of this command and this weird change. Please help!

EDIT 1: The behavior of the user change in root prompt was only once and was never seen again.

1 Answers1

1

The behavior of sudo su - is as follows:

  • This will open a login shell, so /etc/profile, .profile and .bashrc are loaded and this will take the user to the root's home directory and will use the root's environment.

As discussed in the question's comments, the other approach to use a root shell is to run sudo -i. The behavior of sudo -i is as follows:

  • It is nearly the same as sudo su - The -i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profile, .bashrc or .login will be read and executed by the shell.

The reason sudo -i is preferred over sudo su - is the command will log as the user used, not as root, enabling easy auditing of the commands (who ran what) in a multi-user environment.

On the other part of the question (why is the prompt showing as a different user) it is unknown for the time being why that behavior was shown in the first place. Since the environment had some other auditing software installed (WebADM to be specific) something was done by that user. That behavior was not reproducible and was more of an edge case.