How to become root user in Ubuntu

In this article, you will learn how to become the almighty root user on Ubuntu. You will therefore be able to carry out various administrative tasks like package installation and removal, system related commands as well as system configuration.

1 – Root user

Root users in linux have powerful administrative privileges which allow them to carry out important tasks or invoke sensitive commands. It is therefore important for beginners to understand root user and its significance in Ubuntu and in Linux in general.By default, on the latest distributions of Ubuntu, a root user with a strong protected password is no longer provided. The concept of the ‘sudo’ functionality was therefore introduced in order to allow users to perform different administrative operations which require higher privileges.
When Ubuntu is installed, the first user that is created will have the sudo privileges or rights. It will have full control and will therefore be added to the list of the so called sudoers in the file /etc/sudoers. In order to carry out the following root user operations , you would need to be a sudoer.

2 – Becoming root

Open up your Ubuntu Terminal and execute the following command which will will you log in as a superuser :

su –

You will be asked for the password for the root. Just provide the password and press Enter.

As shown above, you can now see the “#” sign on the command prompt. congratulations, since this means that you are logged in as root.

It is possible that the following authentication failure message will be returned when you enter the root password. No worries, since this means that the root account is currently blocked.

Later you will learn how to lock and/or unlock the root account.

In order to become a root user from a normal user account (unprivileged) in case there is no root password that was already set, you can use the following command:

sudo -s

When requested, provide the password of your Ubuntu user. To become a root user using this method, the normal user would have to be a member of the sudo group.

By default, as mentioned earlier, the first user that was created during the Ubuntu system installation belongs already to the sudo group.

As you are now logged in as root, you can carry out all administrative tasks on Ubuntu.

Here is an example how this works.

The file host.conf under /etc/ would need root privileges in order to make changes to it. As a normal user, when you open it using the command :

nano host.conf

You will see the following message :

as shown below.

Because the user is not authorized to write changes to the file above, you see the file as unwritable.

Only if you are logged in as root will you be able to edit the file or if you use the sudo command when opening the file.

When logged in as root, you will see the file as shown below :

Be careful when logged in as root since any small overlooked change on a sensitive system file can be disastrous to the entire system.

You can now become a normal user by using the exit command as shown below:

3 – Temporary root

There is an alternative way to logging in as root in the command line and that is by using the sudo command when you invoke other commands. This will enable you to behave as root in your current active session only.

For instance, you can edit the file host.conf that you opened earlier as root but this time using sudo as follows:

sudo nano host.conf

This has the advantage of allowing you to carry out tasks which require root privileges when the root account, as we saw above, in in blocked state.

You may be interested to read : How to create a Sudo user on Ubuntu

4 – Unlock root account :

When the root account is locked, you will see the message below :

This is normal since most Ubuntu installations lock this account by default.

You can proceed to unlocking it by executing the following command as sudo:

sudo passwd root

Once you provide a new password twice, the system will update the password of root and will therefore unlock the root account.

If for some reason you want to lock it again, you can invoke the following command:

sudo passwd -dl root

5 – An alternative way to changing the root password

Another method which allows you to change the root password will be outlined below.

Since only a root user has the possibility to change his password, you would therefore need to login in as root. Run the command below to do so:

sudo -i

Go ahead and enter the password before pressing Enter.

You may be interested to read: How to use sudo without having to enter a password in Ubuntu

You can now change the root password since you are logged in as root. Run the command below :

passwd

You may be interested to rad: How to disable user accounts and enhance password authentication in Ubuntu

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu
Show Buttons
Hide Buttons