How to reset root password in Linux

Home > Search > How-to

  1. Restart the Linux machine.
  2. At the Grub boot loader, press e.
  3. Locate that line that begins with linux or linux16. If this line contains "rhgb quiet", remove "rhgb quiet". Add init=/bin/bash to the very end of the line. Note: The linux or linux16 information is in the Grub configuration file.
linux16 /vmlinuz-3.10.0-327.10.1.el7.x86_64 
root=/dev/mapper/centos_lxserve01-root ro crashkernel=auto LANG=en_US.UTF-8 init=/bin/bash
  1. Press ctrl x.


You should now have a shell prompt.

By default, the / (root) filesystem is mounted with the ro (read only) permissions. The mount command can be used to see this.

bash-4.2# mount | grep -w "/"
/dev/mapper/centos_lv-root on / type xfs (ro, relatime,attr2, inode64)


Remount the / (root) filesystem with rw (read write) permissions.

bash-4.2# mount -o remount,rw /


Use the mount command again to confirm that the root filesystem now has rw permissions.

bash-4.2# mount | grep -w "/"
/dev/mapper/centos_lv-root on / type xfs (rw, relatime,attr2, inode64)


Use the passwd command to reset root's password.

bash-4.2# passwd
New UNIX password: ********
Retype UNIX password: ********


Create the hidden file .autorelabel in the / (root) directory to cause SELinux to automatically relabel the context of the / (root) filesystem.

bash-4.2# touch /.autorelabel


Ensure the hidden .autorelabel file was created.

bash-4.2# ls -la /


Boot the system.

bash-4.2# exec /sbin/init


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.