Linux Single User Mode Reset Root Password

To do this reboot the Server as soon as you get the boot screen press ‘e’ (stands for edit) from keyboard. After you press ‘e’ from keyboard you would see a lot of text which may be clipped as per the size of your screen. Search for the text “rhgb quiet” and replace it with “init=/bin/bash” without quotes.
Once done editing press ‘ctrl+x’ and it will start booting with specified parameter. And you will get bash prompt. Now check the status of root partition by running following command on the single user mode.

# mount | grep root

You may notice that root partition is reported to be ‘ro’ (Read Only). We need to have read-write permission on root partition to change the root password.

# mount -o remount,rw /

Also cross check, if the root partition is mounted with read-write permission mode.

# mount | grep root

Now you can change the root password by typing the passwd command. But that is not done. We need to relabel SELinux context.  If we skip relabeling the whole SELinux context we would be able to login using using password.

# passwd root
# touch /.autorelabel

Reboot and login again to root account and see if everything works ok or not?
# exec /sbin/init

Or

To enter into single user mode; Go to second last line (Starts with linux 16 or linuxefi) using up and down arrow then  modify the ro argument.
Modify it to “rw init=/sysroot/bin/sh”. Once done, press “Ctrl+x”

# chroot your system
# chroot /sysroot

reset the root password.
# passwd

Update SELinux information.
# touch /.autorelabel

Exit chroot
# exit

Reboot your system.
# reboot

Login with new password.

This entry was posted in Fedora, Linux, Redhat. Bookmark the permalink.

Leave a Reply

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