How to reset forgotten password in CentOS

Hi Friends,

After a long time, I am writing new post. Due to busy schedule, I did not get time to write post. By the way, today I will share how you can reset the forgotten password for your CentOS machine.

It is very obvious to forget the stuff that we use generally. To avoid such incident, we are following some old technique, like writing the password in a diary or phone, saving it in browser, using same password for every account, etc. I must tell you my friends that it is not safe and secure as well. That is why, everyone has his own technique to store their confidential stuffs.

I also forget password for many website accounts, like Facebook, Gmail, etc. However retrieving these password is very easy, if we have access to our mobile number.

Have you ever think what will you do if you forget the password of your CentOS machine. Most of you will format the hard drive and reinstall the OS. But this is not  a solution as your data will be lost.

In this post, I will show you how to reset the password of your CentOS machine, if you forget it.

This post will only work if you have direct access to the machine or serial terminal access with boot menu options. You cannot reset the root password if you are remotely connected, since you need boot menu access for this.

Here is the simple steps:

  1. Start/Restart your machine. You will get boot menu first. We will be given only 5 seconds at the boot menu to select the operating system kernel to boot into. This 5 seconds is very important, because this allows us allows to select different kernels or edit existing kernel parameters before booting. To stop the timer, you can use up/down arrow keys. This will stop the timer and you will have enough time to edit the kernel or choose the different kernel.
  2. Now at the boot menu, press ‘e’ to edit the existing kernel at boot level.
  3. We will now edit the kernel. Scroll down to the list until you see the line underlined below ( ro ) . What we need to do is to change that ro to rw (i.e. from read-only to read-write) and start into a bash shell. This should look like this rw init=/sysroot/bin/sh. Change the code as suggested.  rw init=/sysroot/bin/sh
  4. After changing that, press Ctrl + X  on your keyboard to start the system into single user mode using the bash shell specified above. In this mode, we will change the root password or any password for the user account.
  5. In the single user mode, run the command as shown below:chroot /sysrootchroot runs a command or an interactive shell from another directory, and treats that directory as root. This process is called changing root and the new root directory is referred to as chroot jail.
  6. Now we are all set. We can now set the password for any user account including root. To change the password of the user account, use “passwd <useraccount name>”, like passwd root and it will give you the password prompt to change the password. Provide the password twice. I have used a weak password, that is why I am getting “BAD PASSWORD” in the below snapshot.
  7. After creating the password, run the commands below to update SELinux parameterstouch /.autorelabel
  8. Exit and reboot the system. I hope you know how to reboot the system via command line. Once the system restart, use your new password. Cheers!!! You are now logged into your system.

 

I have uploaded a video on YouTube. You may also check it:

 

 

Let me know if you face any issue in resetting the password. Thank you. 🙂

Powered by Facebook Comments

2 Comments

  1. Pretty nice post. I just stumbled upon your blog and wanted to say
    that I’ve really enjoyed surfing around your
    blog posts. In any case I will be subscribing to your rss feed and I hope you write again soon!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.