What is root user in linux

What is the root user?

If you use sudo su — or sudo -s you will have full root privileges. Is this root user an official user or is it from Canonical?

~$ sudo su - [sudo] password for username: root@lp:~# id uid=0(root) gid=0(root) groups=0(root) root@lp:~# pwd /root root@lp:~# 

root is the all powerful uber-user. root exists in Unix and all versions of Linux. Some Linux versions require you to set up a password for root others such as Ubuntu don’t and use sudo instead.

2 Answers 2

Yes the root user is an official one.

That user comes from a long line of historical influences. It’s the conventional name of the user who has all rights or permissions. Most Unix-linke operating systems have a root user. It’s not always called «root». You may know the Administrator of Windows operating systems.

The sudo program allows one to perform some action as root, such as run a command, run a shell, or log in (in a terminal only). Using sudo allows one to access root privilege only as needed, conforming to the principle of least privilege. The sudo program also provides control over the execution environment for the commands run with it, i.e. whether root’s user configurations or your own are used when commands are run.

In Ubuntu, logging in as the root user directly is disabled by default, to make it less likely that one will cause damage to the system or create security problems by making some mistake as root.

The root user can do things that a normal user cannot for example:

  • Change the owner and permissions of files/directories, regardless of the current owner or permissions
  • Bind network ports below 1024

The root user always has the UID 0 and can be identified by this UID. It is possible to create another user called root, but not for there to be two users with the same UID, hence, there is only one root. It is compulsory to have such a user.

Short digression about sudo :

The sudo program works because it has the «suid-bit» (set user id bit). This allows any user to run the program as the owner of the program. Obviously, this is an enormous security risk, and so sudo performs strict checks to see whether the user attempting to run it has the right to use sudo at all, and which commands they are allowed to run with it. This configuration is stored in the file /etc/sudoers , which should only be edited with the visudo command (you need sudo to run visudo ). During installation, one sets up a first user account in Ubuntu. This first user will automatically have the right to run any command with sudo .

If the sudo executable or /etc/sudoers have wrong permissions, sudo will refuse to run.

Источник

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:

Читайте также:  Linux get lines in file

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?

Root User 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?

Sudo Sandwich xkcd

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.

Читайте также:  Файловый сервер linux ubuntu

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.

Читайте также:  Linux mint как удалить

Источник

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.

Hierarchy of Directories in Linux

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.

Run Commands Without sudo Privileges

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!

Источник

Оцените статью
Adblock
detector