In this article, we’ll explain easy steps to recover root password in Linux.
In case, you forgot root user password in Linux, use this method to gaining access to the instance.
Easy steps to Recover Root Password in Linux
1. Reboot the system.
2. Interrupt the grub2 menu by pressing “e” to edit when prompted with the grub menu.
3. Move the cursor to the end of the line that specifies the kernel (vmlinuz). You may want to remove all other consoles other than TTY0, however, this step may not be necessary for your environment.
4. Append rd.break (no quotes), which will break the boot process just before the control is handed from initramfs to the actual system.
5. Ctrl+x to boot.
A root shell is presented with the root filesystem mounted in read-only mode on /sysroot.
Remount it with write privileges as /sysroot.
# mount -oremount,rw /sysroot
Switch to a chroot jail.
# chroot /sysroot
Change the password for the desired user.
# passwd example-username
If you use SELinux, you should consider re-labeling all files before continuing the boot process. Skip this part if you don’t use SELinux.
# touch /.autorelabel
Use the exit to exit the chroot jail. Use exit a second time, and the system will cleanly boot from the point we interrupted it.
In this article, we have shown you easy steps to recover root password in Linux.
Get high performance Intel Xeon duel E5 series server and KVM VPS instantly.