Centos 7 recover root password

Sometimes you need to reset root password from a Centos 7 system.

Here I will show an easy way, not the only one.

First you’ll need access to grub boot screen, if system it’s running you can send an Ctrl+Alt+Supr key combination

grub load screenat this point we can press the key e to edit boot sequence

edit grub centos 7we need to move down to the line linux16

edit grub centos linux16we should append rd.break at the end of line

edit grub centos 7 append rd.breakand press Ctrl+X to boot with line modifications.

If we edit all correctly we will have a shell in emergency mode

centos 7 emergency modein rescue mode mount point / can be accessed under /sysroot directory, but it’s on readonly, we need to remount with write permissions.

mount -o remount,rw /sysroot

afther this we will do a chroot in this dir to access to all commands

chroot /sysroot/

now we can change root password executing


reset_passwd_centos_7_chrootfinally we need to force our system to relabel selinux file context because in emergency mode selinux it’s not enabled

touch .autorelabel

finally we need to exit from chroot


and reboot our system to make a normal boot


now you should have root access using edited password