Knowledge Base
MilesWeb / How-Tos

How to Reset the Root Password in CentOS/RHEL7?

Approx. read time : 3 min

Generally, it’s an easy way to reset the root password if you’re already logged in with the root privileges. However, if you forget the password and need to change it, here’s an article for you.

To reset the root password on CentOS7/RHEL 7, you need:

  1. A working GRUB root loader
  2. A working operating system

Steps to Reset Root Password on CentOS 7/RHEL 7

Method 1 : Rebooting and Editing Grub2

Reboot the system and press any key to auto-boot from the default kernel. Then, press “e” after selecting the kernel line to enter the Grub Edit Mode

Grub Edit Mode

After you press the “e” key, scroll down, go to the Linux 16 line, and remove the rhgb, quiet and LANG parameters.

For moving at the end of the line, press ctrl+e, move to the front, and press ctrl+a.

The Linux16 line will be linuxefi on the UEFI system.

Method 2: Appending the rd.break to kernel

When you are in edit mode, go to the line starting with linux16 and append rd.break at the end of this line.

rd.break to kernel

This will make the machine boot into emergency mode, giving you root user privileges without entering a root user password. Even though the root user hasn’t been set, this still works.

Reboot the System

Press CLTR+x after appending the rd.break to the kernel. This will help to reboot the system into emergency mode.

system reboot

Remounting the sysroot

Firstly, we will remount the sysroot file system in read-write mode and then use the chroot to get into a chroot jail.

# mount -o remount, rw/sysroot

# chroot /sysroot

Resetting the Root Password

Type a password command in the command line and set the new password for the root user. You might even get into some warnings like “password fails directory check” if your password is weak. You can ignore the warning and set the password you want.

# passwd

resetting root password

SElinux relabeling

All the unlabeled files, which include the shadow files, get relabelled during the booting. The hidden files auto-relabel the files changed outside their regular context, like the file/etc/shadow.

# touch /.autorelabel

Sync

If you want to flush the cache of the disk, type the command given below:

# sync

Reboot

Type the exit command twice and leave the chroot environment and log out. The system will apply some SELinux contexts and reboots.

Conclusion

By following the steps given above, you can easily login to CentOS/RHEL using the new password.

Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna