In this tutorial, we will learn how to reset the root password in Ubuntu.
Most of the average users forget their passwords. According to Microsoft Research, the average user has 6.5 passwords shared across 3.9 different sites. So we know people forget passwords which is why they prefer sticking to sharing the same password across accounts.
But when it comes to such high risk accounts like the server root user, it’s necessary to ensure a really strong password.
What is Recovery Mode?
The method is easy. You don’t need to reinstall the operating system. The main step is to boot into the recovery mode.
What is recovery mode? This mode loads some of the fundamental services and drops you into the command line mode. The user is logged in as the superuser or root user. This mode is used to repair the operating system. Whenever the system fails to boot, we use recovery mode to repair it.
For more details, check the Ubuntu Official Documentation.
Let’s begin with the process on how to reset the root password.
Reboot to the Grub menu
GRUB stands for GRand Unified Bootloader. When we boot the system, the GRUB menu is displayed. The main purpose is to load the Linux kernel into the main memory and turn over the execution from BIOS to Kernel. It provides the list of boot entries or the list of operating systems installed.
For more details, check the GRUB Official Documentation.
So, the user needs to restart the system and wait for the GRUB menu to appear. Note the following steps:
- Restart the System.
- At the time of boot up, hold the left shift key ( If Ubuntu is the only operating system)
- But if it is dual, the menu might appear automatically. The dual or multi-boot system states that there are other operating systems like Windows or Linux distributions installed in the system.
You will be prompted to the following screen as shown below:
It might be possible that only two choices appear i.e. Ubuntu and Advanced options for Ubuntu. In such a scenario, opt for the “Advanced options for Ubuntu”. The user will be prompted to the same screen as given above.
Select recovery mode
The next step is to select the recovery mode from the GRUB’s menu. The user will see the instructions at the bottom of the screen. Press the arrow keys to go through the options. Follow three simple steps to enter the command line to reset the password.
- Hit the down arrow key and opt for the second option i.e. recovery mode.
- Press enter key to select the mode.
- The following dialog box will appear:
- Same as used before, press the down arrow key and select “root”.
- Hit enter and the user will be prompted to the command line.
The root option was selected to enter into the command line so that we could reset the password.
Commands to reset the root password in Ubuntu
We will use the passwd command to reset the password again. The passwd command is used to change the password of the user account as well as root user has the privilege to change the password of another account.
For more details, Check the Password Official Documentation.
Let’s go ahead with the steps below to reset the root password in Ubuntu.
1. Remount the file system
As you know the current file system is in read-only mode. Therefore, the user needs to change the permission to read-write. For this, we will use the mount command. Mount the root file system in read-write mode.
Check the Mount Official Documentation for more details.
Let’s have a look at the command below:
mount -n -o remount,rw /
2. Change the password using passwd command
The user has to use passwd followed by the username. If you are the superuser, use “root” as username, otherwise mention the username of the account.
To do so, type the following in the terminal:
passwd root OR passwd username
You will asked to enter the new password. Remember to type the strong password. You can also follow the guidelines for stronger password requirements.
3. Reboot the system
Now type in reboot in the terminal and you’re good to go ahead and login to your root account. That’s it. Login again to the system and continue with your work!
The tutorial was about how to reset the password in Ubuntu. We have successfully learned the steps which includes selecting the recovery mode and then opting for root to open command line. The commands are successfully described above. If you face any issue, do let us know in the comment section.