How to reset CentOS 7 root password using console

If you have lost the root password of your CentOS 7 system and have access to the console directly or using KVM, you can reset the password following the instructions below.

1) Reboot the server, you will see the grub menu.

CentOS 7 grub menu

2) Press “e” to edit. You will see the edit screen as shown below.

centos 7 grub edit

3) Find the line starting with linux16

In the fine, find

Delete everything after that and replace with “rd.break”, so the line looks like the following

CentOS 7 enable emergency mode

4) Boot the system to the emergency mode by pressing CTRL + X, you will get a prompt like the following

CentOS 7 Emergency Mode Command line

5) Mount /sysroot in read-write mode. and chroot to the file system

6) Reset the root password with passwd command

7) SELinux won’t allow modifying system files like /etc/shadow, to allow the change, create a file

7) Now reboot the system by typing the “exit” command two times

After rebooting, you will be able to log in to the system with the new root password.

Back to CentOS 7

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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