Skip to main content
How To

Set Root Password in Ubuntu

If you really want a separate password for the root account in Ubuntu, here's how to do that.

Sagar Sharma

Unlike many distributions like Fedora, in Ubuntu, you are not given any option to set a root password during installation.

You create a user and that user has sudo access for system management tasks.

But if you want, you can set the password for the root account.

However, for most people, it is not required as you can switch to the root user like this:

sudo su
use root account without setting up the root password in Ubuntu using sudo

Still want to set a separate password for the root? Let me show how to do that.

How to set a root password in Ubuntu

Make sure you use different passwords for the root account and sudo as using the same will be a security threat!

Prerequisite to set the root password: A user account with the superuser privileges

To change your root password, all you have to do is execute the following command:

sudo passwd root

Let's breakdown the command:

In summary, the passwd command was used with superuser privileges to change the root account's password.

Once you execute the above command, it will ask you to enter your new password:

setup root password in Ubuntu

That's it! Now, you can log in as a root using the following command:

login as a root in Ubuntu

To switch back to the normal user, you can execute exit command:


How to disable root account in Ubuntu

I would advise you to disable the root account as you can achieve everything with sudo (which I mentioned at the beginning of this guide).

Or you no longer want to have a root account enabled. And in all cases, it can be disabled as it was by default easily.

To do so, you'd have to use the following command:

sudo passwd -dl root

This command will delete the existing root password and lock the root account (don't worry, it can be enabled again by the above method).

Once you execute the above command, you can no longer use the root account:

disable root account in Ubuntu

You can lock users too! Here's how to do it

There are multiple ways to lock the users in Linux and if you want to do so, we have a detailed guide for that purpose:

How to Lock and Unlock User in Linux Command Line
How do you lock a user account in Linux? Even more importantly, how do you unlock the user in Linux? Learn various ways of locking and unlocking users in Linux command line.

I hope you will find this helpful.

Sagar Sharma