On Ubuntu and other Linux operating systems, there are primarily three types of users: root, sudo, and user with limited or no administrative permissions. The root user is created automatically once the operating system is installed and has no limitations regarding system permissions. So to keep the system secure, it is imperative to change its password time after time.
2- Ways to Change Ubuntu Root Password
The root user is Ubuntu’s default account and is primarily used to carry out administrative tasks that even the sudo user cannot access. To change the root user password in Ubuntu, there is no need to enter the old password, so the upcoming methods can also be used in case the password is forgotten. This guide will explain two ways to change the root password in Ubuntu.
Through GRUB Menu
The GRUB is a bootloader in all Linux systems that is used to select from multiple operating systems and provides recovery options. So to change the Ubuntu root password via GRUB reboot the system in the GRUB menu and press e after selecting Ubuntu operating system:
Next, move the cursor down to the code line stating: ro quiet splash $vt_handoff and then remove this part:
Replace it with the below code line that primarily boots the system with bash shell along with permissions to read and write the file system:
rw init=/bin/bash
Further for validation, check the permissions for the file system by executing:
mount | grep -w /
Now use the passwd command along with the root account name, next enter the new password twice:
After that reboot the system by using the below command that replaces the current shell process with the /sbin/init process
exec /sbin/init
To verify the root password change login to the root account by using:
su
How to Show/Unhide the GRUB Menu in Ubuntu
In Ubuntu, the GRUB menu may not be showing on the startup, so in that case, unhide it by making some changes in the GRUB configuration file:
sudo nano /etc/default/grub
Here in the configuration file set the timeout style to menu and also add the number of seconds for which the menu will be displayed:
Through Terminal
The second method to change the root password on Ubuntu is via the terminal, this method is a lot simpler and easy, simply use the below command:
sudo passwd root
Conclusion
This guide discussed two ways to change the root password in Ubuntu: via its GRUB menu and the terminal. The GRUB menu can be primarily used if users cannot log in due to password forget issues. On the other hand, the second method is a lot more convenient, though the same passwd command is used in both methods.