Skip to Content

How to Access Root Account in Ubuntu Linux

The root account is the most powerful user in a Linux system, with full administrative privileges. However, in Ubuntu, the root account is disabled by default for security reasons. This article will explain how to access the root account in Ubuntu Linux, and what are the advantages and disadvantages of doing so.

What is the root account?

The root account, also known as the superuser, is a special user that can perform any task on a Linux system, such as installing or removing software, changing system settings, creating or deleting users, and more. The root account has no restrictions or limitations, unlike regular users who need to use the sudo command to run commands with root-level privileges.

The root account is identified by the user ID (UID) of zero, and usually has the username of root. The root account also has its own home directory, which is /root, and its own password, which is separate from the password of other users.

Why is the root account disabled in Ubuntu?

The root account is disabled in Ubuntu by default, meaning that you cannot log in as root or use the su command to switch to the root user. This is done to prevent accidental or malicious damage to the system, as well as to protect the system from external attacks. If the root account is compromised, the attacker can gain complete control over the system and cause irreparable harm.

Instead of using the root account, Ubuntu uses the sudo command, which allows a permitted user to execute a command as the superuser or another user. The sudo command requires the user to enter their own password, not the root password, and logs all the commands that are run with sudo.

This way, the system administrator can monitor and audit the system activity, and revoke the sudo privileges of any user if needed.

The sudo command also has some advantages over the root account, such as:

  • It reduces the risk of typing a wrong command or making a mistake that could damage the system.
  • It allows the system administrator to grant different levels of access to different users, depending on their needs and roles.
  • It prevents the user from running commands with root privileges unintentionally or habitually.

How to access the root account in Ubuntu?

Although the root account is disabled in Ubuntu, it is still possible to access it if you really need to. However, this is not recommended unless you are an expert and fully aware of what you are doing.

You should always use the sudo command whenever possible, and only use the root account for specific tasks that require it.

There are two ways to access the root account in Ubuntu:

Method 1: Use sudo -i or sudo -s

The easiest and safest way to access the root account in Ubuntu is to use the sudo -i or sudo -s commands, which start a root shell, allowing you to enter root user commands without using sudo. The difference between the two commands is that sudo -i runs the shell as a login shell, which means that it reads the root user’s profile files, such as .bashrc and .profile, and sets the environment variables accordingly. On the other hand, sudo -s runs the shell as a non-login shell, which means that it inherits the environment variables of the current user.

To use this method, open a terminal and type:

sudo -i

Use sudo -i or sudo -s

or

sudo -s

You will be asked to enter your own password, and then you will see a prompt that indicates that you are now the root user, such as:

root@ubuntu:~#

To exit the root shell, type exit or press Ctrl+D.

Method 2: Set the root password and use su or login

Another way to access the root account in Ubuntu is to set the root password and use the su or login commands, which allow you to log in as the root user or switch to the root user from another user. However, this method is not recommended, as it poses a security risk and may cause problems with some graphical applications. You should only use this method if you have a valid reason and know what you are doing.

To use this method, you need to first set the root password, which is not set by default in Ubuntu. To do this, open a terminal and type:

sudo passwd root

Set the root password and use su or login

You will be asked to enter your own password, and then the new root password twice. Make sure to choose a strong and secure password, and do not forget it.

Once you have set the root password, you can use the su or login commands to access the root account. To use the su command, type:

su -

or

su root

You will be asked to enter the root password, and then you will see a prompt that indicates that you are now the root user, such as:

root@ubuntu:~#

To exit the root shell, type exit or press Ctrl+D.

To use the login command, type:

login

You will be asked to enter the root username and password, and then you will see a prompt that indicates that you are now the root user, such as:

root@ubuntu:~#

To exit the root shell, type logout or press Ctrl+D.

Conclusion

The root account is the most powerful user in a Linux system, but it is disabled by default in Ubuntu for security reasons. To run commands with root privileges, the sudo command is advised.

However, if you need to access the root account, you can use the sudo -i or sudo -s commands to start a root shell, or set the root password and use the su or login commands to log in as root. You should only use the root account for specific tasks that require it, and always be careful and responsible when doing so.