- What is Root Account in Linux
- Short History
- How do I become a Root User on Linux?
- What is the Sudo Group?
- Back to the Root User
- Who Is Root? Why Does Root Exist?
- What is root?
- Gaining Access to root Permissions
- Root User in Ubuntu- Important Things You Should Know
- What is root user? Why is it locked in Ubuntu?
- How to run commands as root user in Ubuntu?
- How to become root user in Ubuntu?
- How to enable root user in Ubuntu?
What is Root Account in Linux
The root account, or root user, has the highest privilege over the system, having complete control over it.
They can easily install any program with the highest privilege, create a user account, assign permissions, and give different privileges to users’ accounts.
Short History
The root account is created by the system administrator who sets up the system or server.
The default user ID for the root user in most Linux distributions is 0.
How do I become a Root User on Linux?
To log into the system as the root user, you need to use “root” as the username and the password that the system administrator used while setting up the system or server.
However, it is not recommended to directly access a Linux system with a root user; instead, create a normal account and add him to the sudo group.
What is the Sudo Group?
The sudo group exists in most Linux systems and holds root level privileges. If you add your normal user to this group, you will have access to those root level privileges.
Only the root user or a user with sudo access can add a normal user to the sudo group.
Once the normal user is added to the sudo group, they can easily execute any command with the highest privileges by adding sudo in front of each command.
$ sudo apt update
After that, they will require the current user’s password to execute the command.
$ sudo apt update [sudo] password for linuxtldr:
Back to the Root User
Having access to the system as the root user lets some applications or packages act smartly (referring to malware) to get system access without user awareness.
In those cases, it is recommended to create an application profile by using a program like SELinux or AppArmor for Red Hat or Ubuntu.
That’s all for now. If you have any suggestions for adding more to this article, do let us know in the comment section.
Who Is Root? Why Does Root Exist?
Have you ever wondered why there is a special account named root in Linux? Do you know what are the recommended best practices to use this account? Are you aware of the scenarios where it must be used and those where it doesn’t? If you answered “yes” to one or more of these questions, keep reading.
In this post we will provide a reference with information about the root account that you will want to keep handy.
What is root?
To begin, let us keep in mind that the hierarchy of directories in Unix-like operating systems has been designed as a tree-like structure. The starting point is a special directory represented by a forward slash (/) with all other directories initially branching off from it. Since this is analogous to an actual tree, / is called the root directory.
In the following image we can see the output of:
which illustrates the analogy between / and the root of a tree.
Although the reasons behind the naming of the root account are not quite clear, it is likely due to the fact that root is the only account having write permissions inside / .
Additionally, root has access to all files and commands in any Unix-like operating system and it is often referred to as the superuser for that reason.
On a side note, the root directory (/) must not be confused with /root , which is the home directory of the root user. In fact, /root is a subdirectory of / .
Gaining Access to root Permissions
When we talk about root (or superuser) privileges, we refer to the permissions that such account has on the system. These privileges include (but are not limited to) the ability to modify the system and to grant other users certain access permissions to its resources.
The reckless use of this power can lead to system corruption at best and total failure at worst. That is why the following guidelines are accepted as best practices when it comes to accessing the privileges of the root account:
Initially, use the root account to run visudo. Use that command to edit /etc/sudoers to grant the minimum superuser privileges that a given account (e.g. supervisor) needs.
Moving forward, login as supervisor and use sudo to perform user management tasks. You will notice that attempting to perform other tasks that require superuser permissions (removing packages, for example) should fail.
Repeat the above two steps whenever needed, and once done, use the exit command to return to your unprivileged account immediately.
At this point you should ask yourself, Are the any other tasks that pop up on a periodic basis that need superuser privileges? If so, grant the necessary permissions in /etc/sudoers either for a given account or group, and continue avoiding the use of the root account at the extent possible.
Summary
This post can serve as a reference for the proper use of the root account in a Unix-like operating system. Feel free to add it to your bookmarks and return as many times as you want!
As always, drop us a note using the comment form below if you have any questions or suggestions about this article. We look forward to hearing from you!
Root User in Ubuntu- Important Things You Should Know
Either you run commands with root privilege like this:
Or you switch user in Ubuntu to root user like this:
In both cases, you’ll have to enter your own user account’s password. But there’s more to root account in Ubuntu that you should know.
When you have just started using Linux, you’ll find many things that are different from Windows. One of those ‘different things’ is the concept of the root user.
In this beginner series, I’ll explain a few important things about the root user in Ubuntu.
Please keep in mind that while I am writing this from Ubuntu user’s perspective, it should be valid for most Linux distributions.
You’ll learn the following in this article:
What is root user? Why is it locked in Ubuntu?
In Linux, there is always a super user called root. This is the super admin account that can do anything and everything with the system. It can access any file and run any command on your Linux system.
With great power comes great responsibility. Root user gives you complete power over the system and hence it should be used with great cautious. Root user can access system files and run commands to make changes to the system configuration. And hence, an incorrect command may destroy the system.
This is why Ubuntu and other Ubuntu-based distributions lock the root user by default to save you from accidental disasters.
You don’t need to have root privilege for your daily tasks like moving file in your home directory, downloading files from internet, creating documents etc.
Take this analogy for understanding it better. If you have to cut a fruit, you use a kitchen knife. If you have to cut down a tree, you have to use a saw. Now, you may use the saw to cut fruits but that’s not wise, is it?
Does this mean that you cannot be root in Ubuntu or use the system with root privileges? No, you can still have root access with the help of ‘sudo’ (explained in the next section).
Bottom line:
Root user is too powerful to be used for regular tasks. This is why it is not recommended to use root all the time. You can still run specific commands with root.
How to run commands as root user in Ubuntu?
You’ll need root privileges for some system specific tasks. For example, if you want to update Ubuntu via command line, you cannot run the command as a regular user. It will give you permission denied error or show ‘are you root’ error.
apt update Reading package lists. Done E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/ W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied) W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
So, how do you run commands as root? The simple answer is to add sudo before the commands that require to be run as root.
Ubuntu and many other Linux distributions use a special mechanism called sudo. Sudo is a program that controls access to running commands as root (or other users).
Sudo is actually quite a versatile tool. It can be configured to allow a user to run all commands as root. You may configure it run only a selected few commands as root. You can also configure to run sudo without password. It’s an extensive topic and maybe I’ll discuss it in details in another article.
For the moment, you should know that when you install Ubuntu, you are forced to create a user account. This user account works as the admin on your system and as per the default sudo policy in Ubuntu, it can run any command on your system with root privileges.
The thing with sudo is that running sudo doesn’t require root password but the user’s own password.
And this is why when you run a command with sudo, it asks for the password of the user who is running the sudo command:
[email protected]:~$ sudo apt update [sudo] password for abhishek:
As you can see in the example above, user abhishek was trying to run the ‘apt update’ command with sudo and the system asked the password for abhishek.
If you are absolutely new to Linux, you might be surprised that when you start typing your password in the terminal, nothing happens on the screen. This is perfectly normal because as the default security feature, nothing is displayed on the screen. Not even the asterisks (*). You type your password and press enter.
Bottom line:
To run commands as root in Ubuntu, add sudo before the command.
When asked for password, enter your account’s password.
When you type the password on the screen, nothing is visible. Just keep on typing the password and press enter.
How to become root user in Ubuntu?
You can use sudo to run the commands as root. However, in situations, where you have to run several commands as root and you keep forgetting to add sudo before the commands, you may switch to root user temporarily.
The sudo command allows you to simulate a root login shell with this command:
[email protected]:~$ sudo -i [sudo] password for abhishek: [email protected]:~# whoami root [email protected]:~#
You’ll notice that when you switch to root, the shell command prompt changes from $ (dollar key sign) to # (pound key sign). This makes me crack a (lame) joke that pound is stronger than dollar.
Though I have showed you how to become the root user, I must warn you that you should avoid using the system as root. It’s discouraged for a reason after all.
You can use su command to switch users in Ubuntu. You can use it with sudo to temporarly switch to root user:
If you try to use the su command without sudo, you’ll encounter ‘su authentication failure’ error.
You can go back to being the normal user by using the exit command.
How to enable root user in Ubuntu?
By now you know that the root user is locked by default in Ubuntu based distributions.
Linux gives you the freedom to do whatever you want with your system. Unlocking the root user is one of those freedoms.
If, for some reasons, you decided to enable the root user, you can do so by setting up a password for it:
Again, this is not recommended and I won’t encourage you to do that on your desktop. If you forgot it, you won’t be able to change the root password in Ubuntu again.
You can lock the root user again by removing the password:
I hope you have a slightly better understanding of the root concept now. If you still have some confusion and questions about it, please let me know in the comments. I’ll try to answer your questions and might update the article as well.