A Step-by-step Guide on How Enable Root User in Ubuntu
When you install Ubuntu, a root account is created. The catcher here is that you do not have the provision to set the password for the account.
Let us assist you in enabling the user account in Ubuntu! This tutorial will help you to understand several other factors too, including how to disable the account and set up a password for your root account. Read on!
Follow the commands mentioned below to find out the root user account password details:
sudo grep root /etc/passwd
The x in the output signifies that the account’s password is empty.
sudo grep root /etc/shadow
Here, ! signifies that the password is locked. What does this mean? Well, this means that the user does not have the access to set a password for the account.
This is an issue, isn’t it? Here is a solution. Following are a few steps that you must follow in order to enable the account and subsequently set a password:
- Temporary Method
- Command-Line and Graphical User Interface Method
- Command-Line Method
Let us understand each method in detail.
You use this method when you want to temporarily enable a root account. Follow the command mentioned below:
Now, if you want to disable an account, just log out of the session and type the following command:
Command-Line and Graphical User Interface Method
When you follow this method, you can easily access your root account either from the GUI or the command line. Use the following command:
sudo -i passwd root
As you can see, the password is updated successfully.
Secondly, here is how you can access the root account through the graphical user interface.
Type root in the first textbox.
Type your root account password.
As soon as you type the password, you encounter an error message. The reason is that there is a security layer in the graphical interface that stops any login until and unless several other configuration files are configured.
This basically provides extra security. In order to log in through the graphical user interface, follow these steps and edit the following files:
After editing these files, next up is to back up the following configuration files:
sudo cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf_backup
sudo cp /etc/pam.d/gdm-password /etc/pam.d/gdm-password_backup
Now, simply, open the “/etc/gdm3/custom.conf” configuration file
sudo vi /etc/gdm3/custom.conf
Moving on, write the following mentioned line under the ‘security’ textbox.
Press save and exit.
Now, open “/etc/pam.d/gdm-password” which is a configuration file.
As soon as you hunt down the following line, add ‘#’ at the beginning of that line, just as shown below.
#auth required pam_succeed_if.so user != root quiet_success
Just save and hit exit on the ‘gdm’ configuration file.
In order to see the changes that you just made, simply reboot the system. To do so, type the following command:
sudo reboot -f
As you have rebooted your system, login into the root account now.
Bam! You can log in to the root account easily.
Additionally, if you want to disable the root account, simply use the following command:
sudo passwd -dl root
Reverse whatever changes you made in the two configuration files earlier.
Delete “AllowRoot=true” from the “/etc/gdm3/custom.conf” configuration file as shown below.
Next, delete the ‘#’ from “/etc/pam.d/gdm-password”.
And you are done!
Using the command-line method, you can easily enable or disable the root account through the command line. Here, you cannot log in through a graphical interface.
Use the following command, to enable the root account:
sudo -i passwd root
The screenshot shows that you can access the root account. Along with that, you can set the password for the root account as well. Now, you can go to your root account by typing the following command:
su – root
Moreover, to disable the root account, enter:
sudo passwd -dl root
To be one hundred percent sure, switch to the root account and see if the process is successful.
If you see the same message like the above image, then yes, you have successfully disabled the account as now you can see that the authentication has failed.
These were few methods to help you enable or disable the root account in Ubuntu.
We hope that the article solved your queries and provided you with a better understanding of the topic. If you have any questions or suggestions, please leave them in the comment section below.