Softpanorama

Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
May the source be with you, but remember the KISS principle ;-)
Bigger doesn't imply better. Bigger often is a sign of obesity, of lost control, of overcomplexity, of cancerous cells

Recover the Root Password in RHEL 7

News

Booting into Rescue Mode

Recommended Links Grub Boot Directly into a Shell Runlevels mount command Serial console
Troubleshooting Errors in /etc/fstab Mounting partitions with chroot Linux root password recovery /etc/inittab /etc/fstab/ Filesystem mount options Reverting permissions in etc to redhat defaults Mounting Linux filesystems

Sudo

YaST

YaST System Repair

Resetting root password on MySQL Minimalistic and Rescue Linux Distributions

Knoppix Linux

Humor Etc

If you boot a RHEL 7 system into the rescue or emergency target, you are prompted for the root password. But what if you have forgotten the password? This exercise shows the steps required to reset a lost password for the root user. During the password-recovery process, you probably won’t have access to documentation. Hence, you should practice the following procedure until you can use it in a crisis:

1.  Use the following command to change the root password to a random string. This command hides the random password from you:

2.  Log out from your session. Try to log in again as the root user. You shouldn't be able to log in to the system with the old known root password.

3.  Reboot the server.

4.  When you see the following message, press a key to access the GRUB menu:

5.  Press E to edit the current menu entry.

6.  Scroll down with the DOWN ARROW key to locate the line starting with linux16. Press CTRL-E or END to move to the end of the line, and then type the string rd.break.

7.  Press CTRL-X to boot the system.

8.  The rd.break directive interrupts the boot sequence before the root filesystem is properly mounted. Confirm this by running ls /sysroot. If you know the contents of the root filesystem, the output should look familiar.

9.  Remount the root /sysroot filesystem as read-write and change the root directory to /sysroot:

10.  Change the root password:

11.  Because SELinux is not running, the passwd command does not preserve the context of the /etc/passwd file. To ensure that the /etc/passwd file is labeled with the correct SELinux context, instruct Linux to relabel all files at the next boot with the following command:

touch /.autorelabel 

12.  Type exit to close the chroot jail, and then type exit again to reboot the system.

13.  It may take a few minutes for SELinux to relabel all files. Once you get a login prompt, confirm that you are able to log in as the root user.