How to reset password of root account in CentOS 7 linux

There is sometimes you forget password of root account and need to reset it. today we will show you how to reset password of root account in CentOS 7 linux.

here we will assume that you have local or console access to your computer.

Here is our environment:

OS: CentOS 7 linux on VMware

Selinux: permissive mode

As you can see in below we have failed to login to our machine due to incorrect password:

reset root passwd in CentOS 7 linux img 1

1- Reboot machine

to reset password of root, we need to reboot our machine to see grub boot menu and change some parameters in line related to kernel.

so, after reboot, in grub menu, select kernel you want too boot and press “e” to edit it.

reset root passwd in CentOS 7 linux img 2

2- Change kernel boot option

after pressing “e”, find line that start with “linux16” word. linux16 word specify kernel too be booted and we should change “ro” in this line to “rw init=/sysroot/bin/sh”.

this will tell kernel to load root in read write mode and also allow us to access shell.

reset root passwd in CentOS 7 linux img 3

reset root passwd in CentOS 7 linux img 4

then press ctrl+x to boot it.

3- Change password of root

Now we have a shell and should change root directory. so issue the following command:

# chroot /sysroot

then enter passwd command and enter your desired password:

# passwd

then exit chroot:

# exit

reset root passwd in CentOS 7 linux img 5

finally reboot machine and login with your new password:

# reboot