How To Set/Change Root Password In Ubuntu?


A root user is a most privileged user account in a Unix based operating system. It has access to all the commands and files of the system. A root user is also called a superuser or administrator because it is needed to perform administrative tasks.

It is used to perform tasks such as installing software, changing the ownership and permissions of files, and managing other user accounts which cannot be done with a normal user account.

Ahead in this article, we will see how we can set/change and disable or remove the password of the root user.

Root account in Ubuntu/Linux Mint

In Ubuntu or a distribution based on Ubuntu, a standard root account is created while the installation of the operating system but no password is assigned to it. Ubuntu comes sudo only by default, which means you are given the ability to execute a task with superuser privileges by using the sudo command. After installing OS If you want you can set or remove the password of the root account by using the terminal.

How to Set/Change the password of root

Since the root account in Ubuntu is created with no password. Use the following steps to assign a password-

1. You can set it in one go by using the following command –

sudo passwd root

This will ask you to enter the new Unix password, enter it and then retype the same password in the next line. Once the password gets assigned it will display a message that password updated successfully.

Now you can check it by using the following command –

sudo -

It will ask you to enter the root password, enter it. Now you will be logged in as root.

2. Another way to set or change the password of root is –

sudo -i

This will prompt you to enter the user password and then switched to root. Now enter the following command to set/change the password.

passwd

Again it will ask you to enter the new Unix password, enter it and then retype the same password in the next line. Once the password gets assigned it will display a message password updated successfully.

Use the following command to logout from the root –

exit

How to disable the root User Account?

Now if you want to disable the root account login, then execute the following command in your terminal.

sudo passwd -dl root

Where,

-d or --delete – The option will delete the password of a user and make a named account passwordless

-l or --lock – This option will disable the password of an account by changing it to a value which matches no possible encrypted value. It adds ! at the beginning of the password.

Now you can verify it by executing the following command-

sudo -

When you enter your root password it will display a message saying authentication failure. It means the root account login has been disabled.

To know more about passwd command see its manual page by using-

man passwd

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.