Categories: Hostripples Featured

How to Reset Root Password in CentOS?

In Linux, you can recover your password easily via a root account. The worst situation arises when you forget your root account password. In such a case, you cannot reset the root account password using a regular user account. This won’t allow a user account to perform such tasks in general.

This article will cover the steps to recover your CentOS root password. So, let’s move ahead to check the steps in the article.

How to recover your Root Password: Step-By-Step

In CentOS, it’s allowed to run the scripts from the initramfs debug the shell at certain points, come with a root shell, and continue till the shell exists.

Whereas this is mostly done for debugging, it can be used to recover a lost root password.

The first step is to reboot the computer and press the “Esc” key shown in the kernel line.

Then, select the kernel line and press the ‘e’ key to edit.  

How to Reset Root Password in CentOS?, Hostripples Web HostingHow to Reset Root Password in CentOS?, Hostripples Web Hosting

Once you press “e” select that entry. After selecting that entry, below kernel command below will be shown.

Once you Press “e” to select that entry. After selecting that entry, below kernel command will be shown.

Type the “End” key to move the cursor to the end of it. Type “rd.break enforcing=0”

After that press “Ctrl+x” to save all the changes.  Next, you’ll see the Initramfs debug.

Now, we have to gain access of reading and writing permissions to /sysroot by typing the below command:  #mount -o remount,rw  /sysroot

Next is to switch into the chroot and type

#chroot /sysroot

Here, /sysroot act like the root of the file system tree. Next, you have to set a new root password.

passwd root

Now, relabel the files and type the command #touch /.autorelabel

Enter the “exit” command twice.

The first one will exit from the chroot jail.

The second one will exit from the initramfs debug shell and reboot the system.

After rebooting the system, you will get the login prompt. Once the reboot is done you can use the newly set root password.  

Wrapping Up

Resetting the root password in CentOS involves booting into single-user mode, remounting the file system as read-write, and then changing the password using the passwd command. This process ensures that access to the root account is regained in case the password is forgotten or lost.


Sourabh Ujjainkar
Sourabh is a Linux Technical Support Engineer at Hostripples, where he utilizes his extensive knowledge of Linux systems to assist clients with their technical issues. With a passion for problem-solving, Sourabh ensures that customers receive prompt and effective solutions. Outside of work, he indulges in his love for travel, exploring new places, and immersing himself in different cultures. In his downtime, Sourabh finds solace in the melodies of music, which helps him unwind and relax.

Recent Posts

The Ultimate Guide to DIY Website Builders for Entrepreneurs

Ah, the joys of building a website! Picture this: You're sitting there in your pajamas, coffee in hand, ready to…

1 week ago

Don’t Ignore These 11 Signs You Need a Hosting Upgrade

Are you feeling like your website is running in slow motion? It can be frustrating when your online presence doesn't…

2 weeks ago

PrestaShop vs OpenCart: Which Is Right for Your Business?

Are you ready to take your online store to the next level? Whether you're running a PrestaShop or OpenCart platform,…

3 weeks ago

Sitemaps: A Guide to Enhancing Online Visibility

Picture this: your website is like a fabulous party happening in the darkest corner of the internet, but nobody's showing…

4 weeks ago

Step-by-Step Guide to Implementing a CDN for WordPress

Picture this: Your WordPress site is like that one friend who's always fashionably late to everything. You know, the one…

1 month ago