Recovering the root password is a trivial task while still logged in as an administrator or a user with full sudo access, but is slightly more involved when an administrator is not logged in. To recover the root password, use the following procedure:
- Reboot the system, press e to edit the selected entry. Move the cursor to the kernel command line (the line that starts with linux16). Append rd.break (this will break just before control is handed from the init ramfs to the actual system). Press Crtl+x to boot with the changes. At this point, a root shell will be presented, with the root file system for the actual system mounted read-only on /sysroot.
- Remount /sysroot as read-write.
switch_root:/# mount -oremount,rw /sysroot
- Switch into a chroot jail, where /sysroot is treated as the root of the file system tree.
switch_root:/# chroot /sysroot
- Set a new root password
sh-4.2# passwd root
- Make sure that all unlabeled files (including /etc/shadow at this point) get relabeled during boot.
sh-4.2# touch /.autorelabel
- Type exit twice. The first will exit the chroot jail, and the second will exit the initramfs debug shell.
Red Hat System Administration III
Contributor: Ananto Yudi Hendrawan Network Engineer - CCIE Service Provider #38962, RHCE, VCP6-DCV firstname.lastname@example.org