Linux SysAdmin & DevOps

CentOS 7 - reset root password

CentOS 7 - If you forgot root password the first thing that might cross your mind would be to boot in single user mode and reset the root password from there. That was working just fine in CentOS 5.x or CentOS 6.x but in 7.0 the things are a little bit different.

It is still possible though.

You will have to follow these steps:

1) Start the system and on the GRUB 2 boot menu press e key for edit.

2) Search for the line containing linux16 and at the end of it add: rd.break enforcing=0

3) Press Ctrl+X to boot the system with the modified parameters

4) The system will boot but the file system is mounted as read-only in /sysroot

5) We have to remount the file system as writable:

switch_root:/# mount -o remount,rw /sysroot

6) Change the file system’s root as follows:

switch_root:/# chroot /sysroot

7) Change the password using passwd command:

sh-4.2# passwd root

8) If you have SELINUX enabled you have to relabel all the files on the next system boot (if you have SELINUX disabled you can just ignore this step):

sh-4.2# touch /.autorelabel

9) Remount the file system as read-only

sh-4.2# mount -o remount,ro /

10) Exit from the chroot environment by simply typing:


11) Reboot

On the next system boot, you will be able to login with the new root password.