Resetting the Root Password of RHEL-7 / systemd
Posted: Wed Mar 23, 2016 5:45 pm
Issue
Please note that in case you are using a USB keyboard or if the system is a virtual guest, the following instructions need to be followed
Note that the above mentioned steps may drop you to a prompt without access to a USB keyboard and do not work in a VM like KVM or VirtualBox. To reset the root password in these environments:
- How to reset the root password of a RHEL-7 / systemd ?
- RHEL-7 ask for a root password even after booting in Single user mode.
- Not able to change the root password in single user mode
- Boot your system and wait until the GRUB2 menu appears.
- In the boot loader menu, highlight any entry and press e.
- Find the line beginning with linux. At the end of this line, append the following:
Or if you face a panic, instead of "ro"change to "rw" to sysroot as example bellow:
Code: Select all
init=/bin/sh
Code: Select all
rw init=/sysroot/bin/sh
- Press F10 or Ctrl+X to boot the system using the options you just edited.
Once the system boots, you will be presented with a shell prompt without having to enter any user name or password:Code: Select all
sh-4.2#
- Load the installed SELinux policy:
Code: Select all
sh-4.2# /usr/sbin/load_policy -i
- Execute the following command to remount your root partition:
Code: Select all
sh4.2# mount -o remount,rw /
- Reset the root password:
When prompted to, enter your new root password and confirm by pressing the Enter key. Enter the password for the second time to make sure you typed it correctly and confirm with Enter again. If both passwords match, a message informing you of a successful root password change will appear.
Code: Select all
sh4.2# passwd root
- Remount the root partition again, this time as read-only:
Code: Select all
sh4.2# mount -o remount,ro /
- Reboot the system using following command. From now on, you will be able to log in as the root user using the new password set up during this procedure.
NOTICE: If typing "exit", the root password will not be changed. Type "exec /sbin/init" is needed.
Code: Select all
# exec /sbin/init
Please note that in case you are using a USB keyboard or if the system is a virtual guest, the following instructions need to be followed
Note that the above mentioned steps may drop you to a prompt without access to a USB keyboard and do not work in a VM like KVM or VirtualBox. To reset the root password in these environments:
- add rd.break instead of init=/bin/sh to the end of the line that starts with linux in Grub2:
- when the system boots, run the following command to remount the root filesystem in read-write mode:
Code: Select all
mount -o remount,rw /sysroot
- then run:
Code: Select all
chroot /sysroot
- eun:
Code: Select all
passwd
- instruct SELinux to relabel all files upon reboot (because the /etc/shadow file was changed outside of its regular SELinux context) -- run:
Note that this may take some time during the next boot.
Code: Select all
touch /.autorelabel
- type exit to leave the chroot environment.
- type exit to log out.
The system will reboot, re-apply all SELinux labels, and present you with a regular login prompt.
Note: If the system is encrypted, the above method will not work. Please refer to the following article: Resetting the Root Password of RHEL-7 for encrypted devices