Skip to main content

How to reset root password in Linux (RHEL,FEDORA) ? What to do if you forgot root password ?

How to reset root password in Linux (RHEL,FEDORA) ? What to do if you forgot root password ?

Today I want to give you some very useful tips on what to do if you have forgotten your root password. 
ATTENTION: This trick will only work if didn’t  setup GRUB password yet.    (if you did – sucks to be you :) )
Use Case:
You want to install something, change permissions on a file  or  do any other action that actually requires root password , which you don’t remember. I would start to panic, If i where you, but wait, there is some small hack you can do, to get back on track.
In this post I will show you how you can become a root without knowing you root password and reset it. I will also give you tips how to protect yourself from this vulnerability.
Let’s start.

1. Boot in Single User Mode

 a. Reboot your computer
 b. Wait until menu say’s to press any key to the Boot/GRUB menu, press any key
   At this point you should see menu similar to this:
grub-menu-image
c. Point to the OS you forgot your  password from and press “e
  
d.  Go to “kernel” line and add word “single” to the end of kernel string.
e. Press “b” to boot with new option for kernel
   Note: If you did something wrong, you could see “black screen of death” but don’t worry, everything you edit in boot menu is temporary, just reboot and you are good to go again.
c. If you did everything correctly you should see command line interface, where you are logged in as “root”.
How cool is that ?

2. Set SELinux to Permissive

a. If you try to change password right away, in RHEL or Fedora you won’t be able to do it because SELinux by default is enforcing.
  Good thing is that we can easily change SELinux enforcing mode. First lets find out the state of SELinux and if it is Enforcing, lets change it to Permissive. Type this in your command line:

4. Change Root Password

You will see that all tokens are updated.  Type ‘reboot’, and after you reboot, you will have your NEW root password. (write it down!) :)

But what if someone else would want to change my password in the same way ?

This is very legit question, and it was my first thought when I found out this easy way to change root password. How to protect yourself ? The answer is to put password on Boot menu.

How to lock GRUB/Boot menu ? ( I will show it on GRUB, however GRUB2 works similarly)

Here are a couple of simple steps how to set password on your GRUB:
 1. Open Terminal and login as root:
Enter your root password.
2. Now type:
3. Enter password you want your grub (this can be different from your root password)  and click enter you will get md5 encoded string.
Let’s say your  md5 string is:
4. Now use your text editor to go to grub.conf file, I use VI:
after “hidemenu” line enter:
password –md5 < paste here your encrypted md5 string>
(in my case it would be: password –md5 $1$sdlfksdlfksdlf/ )
5. Save the file.
6. To check if it works, try logging to Single User Mode, you will set instead of “e” to edit kernels string, you will need to enter password first.
That’s it for today!

Comments

Popular posts from this blog

Top five MLM companies in Pakistan

There are several multi levels marketing (MLM) or direct selling companies in Pakistan since 1999 but some of them are better than the others. We have some big names in the list of MLM companies in Pakistan. These companies are local and international companies and also have a great reputation in the world. Here we are giving some important information about these companies for the people who are searching for their career company in Pakistan. These are the top five MLM companies in Pakistan . These are decided by the top network marketers and by the masters of all kind of marketing in Pakistan. The ELI Enlightenment through learning and implementation (ELI) is one of the best MLM or direct selling company in Pakistan and a pure Pakistani company in the area. This company is working on the educational products. These products are computer courses, ielts, spoken English and some kind of other courses. All courses are in DVD’s. These courses are very expensive in ...

Run Android on Your Computer

Run Android on Your Computer And Run Any VoIP App on It Screenshot of Jar of Beans Android Emulator. by Nadeem Unuth Updated March 20, 2017 There are so many interesting apps there on Android that would be great if you could have them on your computer. There are those games, and there are those communication tools that allow you to save money and to communicate using text, voice, and video. Well, there are things you can do to run VoIP apps like WhatsApp , Viber , WeChat , BBM and all the other apps you find on Google Play on your computer just like you would run them on your Android device. You only have to install software called an Android emulator. It simulates the functions of an Android device on your computer and runs like an operating system within your computer’s operating system.  Your mouse curs...

How to create a contact form with Bootstrap ? (JQuery/PHP/HTML5/JqBootstrapValidation)

How to create a contact form with Bootstrap ? (JQuery/PHP/HTML5/JqBootstrapValidation) ​ How to create contact Form - FREE PDF Code Examples Links to all the resources GIVE ME MY PDF! Hey guys! Today we will talk about such essential feature for any website as contact form. Recently, while working on one of the projects, I had a pleasure combining couple of very nice tools (Bootstrap 3 + JQuery + jqBootstrapValidation), which resulted in minimalistic , but powerful contact form, that would be a good addition to any website. VIEW DEMO            CODE In this post I will walk you through the process of developing this form. Also if you just want to put it in your website, just pulled from my github repo and have fun. Sounds good ? Let’s start. When I was developing my form I had in mind following goals: – Minimalistic design – Track person’s contacts for future commu...