title: “Resetting the Root Password”
date: 2016-01-18T12:42:55
slug: resetting-the-root-password
1.
Boot your system and wait until the GRUB2 menu appears.
2.
In the boot loader menu, highlight any entry and press e to edit it.
3.
Find the line beginning with linux. At the end of this line, append the following:
init=/bin/sh
IMPORTANT
Some systems (notably virtual machines) may have problems displaying correct output when you boot using this procedure. Some characters or even entire lines may be hidden, making the shell difficult to use. To solve this problem, delete the rhgb command from the linux line.
4.
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:
sh-4.2#
5.
Load the installed SELinux policy (-i inital policy load. Only use this if this is the first time policy is being loaded since boot (usually called from initramfs).):
sh-4.2#
6.
Execute the following command to remount your root partition:
sh4.2#
7.
Reset the root password:
sh4.2#
When prompted to, enter your new root password and confirm by pressing the Enterkey. 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.
8.
Remount the root partition again, this time as read-only:
sh4.2#
9.
Reboot the system. From now on, you will be able to log in as the root user using the new password set up during this procedure.
Another Way:
Add the following parameter to kernel boot line in Grub:
rd.break enforcing=0
mount -o remount,rw /sysroot
chroot /sysroot
/usr/bin/password
touch /.autorelabel
mount -o remount,ro /
