Introduction
Forgetting the root password on your Ubuntu system can feel like being locked out of your own home. But fear not, regaining access to your system is not as daunting as it may seem. In this detailed tutorial, we’ll guide you through the process of resetting your forgotten root password on an Ubuntu machine. Note that the following steps require you to have physical access to the machine or the ability to connect to the system via a console if it is a virtual machine or server instance.
Understanding the Root Account
Before we proceed, it’s important to understand what the root account is. The root account is the superuser on the Linux and Unix-like system. It has unrestricted access to all commands and files on the system. Taking control of the root account means you can perform administrative tasks, including changing the password.
Step-by-Step Instructions
Step 1: Reboot into Recovery Mode
- Start by restarting your Ubuntu system. As the machine boots up, hold down the
Shift
key to access the GRUB menu. (On some systems it might be theEsc
key instead). - Use the arrow keys to select the ‘Advanced options for Ubuntu’ and press Enter.
- From the next screen, choose the ‘recovery mode’ option which usually has ‘(recovery mode)’ in its description and press Enter.
Output: You will now see a new page with different recovery options.
Step 2: Drop to Root Shell Prompt
In the ‘Recovery Menu’ you will see several options, navigate to ‘root Drop to root shell prompt’ and press Enter.
Output: You will be taken to a root shell session in recovery mode with a command prompt.
Step 3: Remount the Filesystem with Write Permissions
By default, the filesystem is mounted with read-only permissions. To change the root password, you need to remount the filesystem with write permissions Just type mount -o remount,rw /
and press Enter to remount the filesystem.
This will ensure that you can make changes to system files including the password files.
Output: No visual confirmation, but no errors should mean your filesystem is remounted as read-write.
Step 4: Resetting the Root Password
- Now type
passwd
and press Enter. - When prompted, enter the new password for the root user and confirm it by retyping it when prompted.
Remember: Choose a strong and memorable password, combining upper and lower case letters, numbers, and symbols.
Output: The system will notify you that the password has been updated successfully.
Step 5: Update the Mandatory Access Control System (AppArmor/SELinux)
If your system uses AppArmor or SELinux, you should inform them about the changes. Type touch /.autorelabel
and press Enter if SELinux is employed to relabel the filesystem on the next boot automatically.
Step 6: Resume Normal Boot
- Finished with the recovery process, type
exit
to leave the root shell. - From the recovery menu, select ‘resume’ to continue booting normally.
Conclusion
Once the system boots up, you should be able to use the root account with the new password you’ve set. This tutorial should help regain control of your Ubuntu system when you’ve forgotten the root password. However, it’s crucial to use these powers responsibly and ensure the security of the system.