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

linux16 /boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64 root=UUID=1c419d6c-5064-4a2b-953c-05b2c67edb15 ro no_timer_check console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 elevator=noop crashkernel=auto LANG=en_US.UTF-8

In the fine, find

ro

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

linux16 /boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64 root=UUID=1c419d6c-5064-4a2b-953c-05b2c67edb15 ro rd.break

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

mount -o remount,rw /sysroot
chroot /sysroot

6) Reset the root password with passwd command

passwd

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

touch /.autorelabel

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

exit
exit

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 *