AMP AMP

How to Reset/Recover Forgotten Root User Account Password

To Reset/Recover Forgotten Root User Account Password in RHEL/CentOS 7

Resetting/Recovering Forgotten Root User Account Password in RHEL/CentOS 7 is explained in this article. There are various ways to reset root password and we are going to follow “ Booting into single user mode” type to reset the password.

To try login using with Login Credentials

First let us try to login as root in the CentOS 7 server. If you have forgot your password then try logging in with the user credentials. Now we have logged in using the user1. It is not possible to change the password of the root from the user login.

login


To reset the password

Now boot into single user mode and reboot the Server, as soon as you see the below screen and then Press ' e' from keyboard.

boot_screen

After hitting ' e' from keyboard, you will get the display as shown below. 4

Search for the text rhgb quiet and replace it with init=/bin/bash

After editing press ' ctrl+x' and it will start booting with specified parameter. Now a bash prompt appears.

To change the root password

You should have read-write permission on root partition to change the root password.

bash-4.2# mount -o remount,rw /

Change the root password by typing the passwd command. Relabel SELinux context. If we skip relabeling the whole SELinux context we would be able to login using password.

bash-4.2# passwd root
[Enter New Password]
[Re-enter New Password]

bash-4.2# touch /.autorelabel
Reboot and login again to root account.

bash-4.2# exec /sbin/init

Tag : CentOS Root
FAQ
Q
How to reset/recover the ROOT password in openSUSE?
A
1. Boot the system and select the normal boot menu from the list. Once selected, in the “Boot Options” box type

“init=/bin/bash” if you are using GRUB Boot loader

“linux init=/bin/bash” if you are using LILO Boot Loader
Q
What if I don’t know the username?
A
cat /etc/passwd

Sample output:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin

you can only list the usernames with command:

awk -F':' '{ print $1}' /etc/passwd

Sample output:

root
daemon
bin
sys
Q
how can i see the other username and password after root pass change?
A
follow the link, In /etc/password and /etc/shadow file.
Q
Will this password reset also corrupt my data? Using Centos 6.4 distro?
A
No, your data won’t be corrupted or lost.
Q
How to reset forgotten root password without booting?
A
Not possible, you have boot into single user mode to set forgotten root password.