Set Root Password in Ubuntu
If you really want a separate password for the root account in Ubuntu, here's how to do that.
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
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
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:
sudo
: To execute command with superuser privilegespasswd
: Used to change passwords for user accountsroot
: Indicates a root account
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:
That's it! Now, you can log in as a root using the following command:
su
To switch back to the normal user, you can execute exit
command:
exit
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:
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:
I hope you will find this helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.