Root
The Linux root account is the privileged administrator account. The root account has access to create, read, update, an delete anything on the Linux system. It is a powerful account and if used carelessly could result in crashing the system. So let's try it out!
Learning Objectives
You should be able to:
- Run individual commands with elevated permissions using
sudo. - Switch to the root user using the
sucommand. - Switch back to a regular user account.
Video Walkthrough
Use this video to follow along with the steps in this lab.
sudo
The sudo command can be used to run a single command with elevated privileges.
- Open your Linux terminal.
- Verify your current account.
whoami
-
You should see your regular, non-privileged account (
ubuntu,kali,ec2-user, or something similar). -
Run the following command to try to list the root user's home directory:
ls /root
You should get a permission denied error. Note that all other user home directories will be in /home.
- Run the following command to run
lswith elevated privileges:
sudo ls -a /root
- Depending on the system configuration, you might be prompted for a password at this point.
- Run
whoamito verify your current account. You should still be the same, non-root user.
The sudo command is often used when making changes to system files and settings.
Switching to The root Account
Generally, it is a good idea to switch to the root user only when needed. Regular system usage should be done with a non-privileged account (like the kali user account). But there are times when switching to the root account will be helpful.
- Run the following "substitute user" command to switch users to the root account.
sudo su - root
- The prompt will change to something like:
root@ip-172-31-16-60:~#
- Run
pwdandwhoamito check your current information.
pwd
whoami
- Notice that the current user is now
root, and the working directory is /root. You did notcdto change directories, but by switching users withsu -you basically logged into the system with that user account. Notice that the prompt also changed to showroot@hostinstead ofubuntu@host. - Run:
ls -a
- You should see a listing of the files (including hidden files starting with a period) in the root user's folder. You should not get a permission denied error.
- Run:
exit
- Notice that the terminal program did not exit. You only exited from the root user account. If you ran
exitagain, you would close your terminal.
Reflection
- What is the benefit of computers making you elevate permissions to perform certain tasks?
- What would go wrong if all users were given root privileges?
See Also
Key Terms
- Root User: The superuser account in Unix and Linux operating systems with the highest level of privileges. The root user has unrestricted access to all commands, files, and system resources, allowing them to perform administrative tasks such as installing software, modifying system configurations, and managing user accounts. Due to its powerful capabilities, the root account should be used with caution to avoid unintentional system damage or security risks.