Recovering the Root Password on Linux
This article provides step-by-step instructions for recovering the root password using three different methods: via GRUB, rescue mode, or single-user mode.
Method 1: Using GRUB
1. Edit GRUB at Boot:
- Restart the system and press e at the GRUB menu to edit the boot entry.
- Locate the line starting with linux
- Add the following parameters at the end of the line:
3. Boot into the Modified Configuration:
- Press Ctrl+X or F10 to boot with the updated configuration.
- Remount the system root directory in read/write mode:
mount -o remount,rw /sysroot
chroot /sysroot
5. Change the Root Password:
- Reset the root password using:
passwd root
6. Relabel SELinux:
- Trigger an SELinux relabeling process to ensure proper access controls:
touch /.autorelabel
7. Reboot the System:
- Exit the chroot environment and reboot:
exit
exit
Method 2: Rescue Mode
1. Enter Rescue Mode:
- At the GRUB menu, select the rescue mode option.
- Alternatively, add the following parameter to the kernel line:
2. Login as Root:
- Once in rescue mode, log in as root.
- Update the root password:
passwd root
After successfully resetting the root password, make sure to:
- Reboot the system to apply changes.
- If SELinux was disabled temporarily, ensure it is properly enabled after relabeling.