How to switch to the root user?

QuestionsQuestions8 SkillsProDec, 15 2025
0156

That's a very common and important question when working with Linux!

To switch to the root user in your LabEx VM, you can use the sudo su - command.

Here's how you do it:

sudo su -

Explanation:

  • sudo: This stands for "superuser do" and allows you to run commands with superuser (root) privileges. In LabEx VMs, the labex user has sudo privileges without needing a password.
  • su: This stands for "substitute user".
  • -: This hyphen ensures that you log in as root with root's environment variables (like its home directory and path), making it a full login shell.

After executing sudo su -, your terminal prompt will likely change to indicate that you are now the root user (e.g., # instead of $, and the username will be root).

However, for this specific lab, the current step is designed to introduce you to the whoami command and show you your default username (labex). While knowing how to switch to root is super useful for many tasks, it's not required for this particular step.

I recommend you first try running whoami as instructed in the current step to see your current username.

whoami

After that, you can always experiment with switching to root if you wish!

0 Comments

no data
Be the first to share your comment!