That's a great follow-up question! In Linux, the standard way to switch users is by using the su command (which stands for substitute user or switch user).
Here are the most common ways to use it:
1. Switch to a specific user
If you want to switch to a user named john, you would use:
su john
The system will then prompt you for john's password.
2. Switch to the Root user (Administrator)
To switch to the superuser (root), you can simply type:
su -
Note: The - is recommended because it starts a "login shell," meaning it loads the environment variables and settings specific to that user.
3. Run a single command as another user (sudo)
In many modern Linux distributions (including this LabEx environment), we use sudo (superuser do). This allows you to run a command as another user (usually root) without completely switching your session:
sudo command_name
In this lab, the labex user has sudo privileges, so you can perform administrative tasks by adding sudo before your commands.
Try it out:
If you want to see whoami report a different user, try running:
sudo whoami
It should return root because you ran the command with administrative privileges