Setting Root Password in Ubuntu (And Unset it Later)

Learn how you can set up a root password. Also learn to unset the root password if you don't require it anymore.
Warp Terminal

When you do a fresh installation of Ubuntu, you are not given any option to configure a root password.

Instead, a user account is created and added as sudoer. This user can run commands as root by adding sudo before them.

You could also switch to the root user with sudo:

sudo su
Use root account without root account

However, you may find yourself in a situation where you prefer to run as root and you would also prefer to have a dedicated password to this root user.

If that's the case, this quick tutorial will help you.

How to set a root password in Ubuntu

The strange part of this entire tutorial is even though you never configured a root password, you are going to change it with the password of your liking.

To change (or set) a root password, you can use the passwd command with sudo to change the root password:

sudo passwd root

Once you execute the above command, it will first ask you for a sudo password and then ask you to enter the new root password two times:

Set root password in Ubuntu

From here on, you can access the root user account without any restrictions:

su 
How to use root account in ubuntu

How to unset root password again

We at itsFOSS don't suggest configuring a root account unless you really want as there are various reasons why Ubuntu don't give an option for a root account during installation.

If you want to go back to the previous stage when the root user was locked and you can only access the root account with sudo, then you can lock the root account.

First, switch to the root user using the following:

su 

Now, use the passwd command to lock the root user and delete the root password as shown here:

passwd -dl root
Re-disabling root account in Ubuntu

From here, you can't access the root account directly and if you want to access it, you can still access it as you used to do with sudo su command:

su authentication failure
Reset Forgotten Root Password in Ubuntu [Easily]
You had set up root password in Ubuntu but cannot remember it now? Here’s how to reset forgotten root password in Ubuntu and hopefully in other Debian-based distros.

Wrapping Up...

In this quick tutorial, I went through how you can set the root password and how to revert to the previous state. I don't recommend setting up a root account unless you know what you are up to.

That's it from my side. If you have any queries, leave us a comment.

About the author

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.