reset root password
reset root password

How reset root password on CentOS 7/ RHEL 7

There are times when we forget the root password for one reason or another, so it would be impossible for us to access our system. In this article we will see the steps to follow to reset the root password on CentOS 7 / RHEL .

Steps to reset root password :

Step 1 : Boot Up your system and on the Grub2 boot Menu screen, Press e on the Keyboard :

Grub menu

Step 2 : at the end of the linux16 line, add the following line : rd.break

rd.break

rd.break breaks the boot process before initramfs passes control to systemd.

Then press Ctrl-x to reboot :

reset root password

Step 3 : Mount the file system as Read/write

The mount point /sysroot is in ro (read only) you must put it in rw (read write) with the command below :

switch_root:/# mount -o remount,rw /sysroot/
reset root password
reset root password
reset root password

/sysroot is now mounted in rw

Step 4: change root

Change the root directory with chroot :

switch_root:/# chroot sysroot
chroot mod

Step 5 : change the root password

sh-4.2# passwd
reset root password

Step 6 : Set SELinux relabeling on next boot

sh-4.2# touch /.autorelabel

Step 7 : Exit the chroot mode

Type the command exit to exit chroot mode

sh-4.2# exite
switch_root:/# logout
reset root password

To read this article in French click here.