How To Reset Root User Password in Linux

1>If your Linux server is currently running, you have to reboot it. If it is not yet running, then start it up. At the boot menu, press the ‘e’ key to edit the first boot entry.

2>From the grub options, find the line that starts which start with  “linux16” and go to the end of it. Type  ‘rd.break’ without quotes at the end of this line, as shown below.

3>Press “Ctrl+x” to boot with these options. It will boot  the initramfs with a root shell.

4 >At this point, root file system is mounted is inread only mode to /sysroot and must be remounted with read/write (rw) permissions in order to  make any changes. This can be done with the ‘mount -o remount,rw /sysroot’ command.

5> After the file system has been remounted, change into a chroot jail so that /sysroot can be  used as the root of the file system. This is required so that any further commands we run will be in regards to /sysroot. It can be done by running ‘chroot /sysroot’.


6 > the root password can be reset with the ‘passwd’ command as show below


7> RHEL 7 use SELinux in enforcing mode, so we need to fix the context of /etc/shadow file. This is because when the ‘passwd’ command is run, it creates a new /etc/shadow file. As SELinux is not running in this mode the file is created with no SELinux contexts, which can cause problems when system reboot. Create the /.autorelabel command using ‘touch’


Creating this file will automatically perform a relabel of all files on next boot. Note that this may take some time depending on the number of files present in  the file system.

Enter the ‘exit’ command twice, the first one will exit the chroot jail environment while the second will exit the initramfs root shell and reboot the system.

Once the reboot has completed you will be able to use the root account with your newly set password.



3 thoughts on “How To Reset Root User Password in Linux”

  1. An intriguing discussion is worth comment. I believe that you need to write more on this subject matter, it may not be a taboo matter but generally people don’t speak about such issues.
    To the next! Cheers!!

Leave a Reply

Your email address will not be published. Required fields are marked *