How to reset root password of my Fedora Linux system using GRUB
There are multiple ways of recovering your Linux system if you have forgotten the password for root account. In this article I will discuss about how to do it using GRUB and single user mode.
GRUB provides great flexibility to recover a system by providing on the fly editing of boot options. The standard Fedora Linux systems support single user mode for which no log in is required. The following explains step by step procedure. Though this article takes Fedora system as an example, This procedure will work fine for any Linux system that has GRUB as boot loader and supports single user mode.
When your screen appears similar to the following, interrupt the GRUB to get the list of booting options. Just press any key to interrupt GRUB’s automatic boot sequence.
After you press some key, You will see the screen similar to the following. This screen contains all booting options for your PC. There is only Fedora 6 installed in my system so only one entry appears in this booting list. If you have multiple entries then select the one which has root password problem. You should use UP and DOWN arrows to select an entry.
If you read the help messages shown by GRUB at the bottom of the above screen, it says to press button ‘e‘ to edit the commands before booting. So press button ‘e‘ after selecting the correct entry as mentioned in the previous step. You will see something similar to the following screen after you press ‘e‘ key on your keyboard.
This screen shows the commands for the boot option. Now select the the line that starts with “kernel” as shown in the screen using UP and DOWN arrows. Then press button ‘e‘ on your keyboard again to edit that line. You will see a screen like the following.
Now just press SPACE BAR, then key ‘1‘ and then ‘Enter‘ to append “1” to the existing command. This “1” tells the Linux system to boot in single user mode. In single user mode, Linux gives you shell access with root privileges without prompting for log in. You can also give the word “single” instead of “1“.
Now press ‘b‘ on your keyboard to boot the Linux system with these modified boot command options. Once the Linux complete booting, the screen looks like this and you will see a shell.
Now you have a shell with root privileges so you can change the password of root account with the command ‘passwd‘ and reboot the system for the regular boot.
sh-3.1# passwd Changing password for root. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. sh-3.1#
There are few other methods of resetting root password like using rescue disk and connecting hard drive to another system etc. They will be discussed in other articles.