Reset forgotten root password
Documentation can be lost without a notice. We cannot help it all the time. Even oracle databases cannot guarantee you 100% back up. So it is quite possible that after 99.99% back you password document can be lost or corrupted. So what to do if your Linux server cannot be accessed because of you lost password or somehow you forgot the password. The answer is pretty simple. Reset the password. This process is some easy step by step work. To understand this process we need to be very focused on the steps and we have to do these very carefully. One simple wrong move can give us kernel panic.
so let’s start with the first step. Simply reboot the system and keep a very careful eye on the screen. At the beginning we will get the grub page. Here we have to stop the booting process. We may get very small time to do this. There are two ways to stop this process. First keep pressing up and down arrow. Second keep pressing ESC button. Once the process is stopped then we can select the appropriate kernel from the boot menu. Please see the below image to understand the grub page.
After this we will be into the kernel editing page then we have to go through top to bottom of that page and fine out the line starts with “linux16 /vmlinuz-“. On that line we have to find out the “ro”. That will look like the below page.
Now we need to edit this out and put “rw init=/sysroot/bash/sh” on the place of “ro”. Now it will look like the below image.
As we see bottom of that page that we can give two combinations in there. Either Ctrl+X or Ctrl+C. if we provide Ctrl+C then the process will break and go back to reboot process. But if we provide Crtl+X then it will continue with the changes made to kernel. So we have to hit Crtl+X. after this step is done will get the page shown below.
Once we get this step then we are half way there to reset our root password. Here we have to take control of the root directory with a special permission which we call single user permission. On this step we will run the commands given below.
#chroot /sysroot
#password root
After running these two commands we will be asked for a new password. So we have to provide the new password and system will ask for retype the password. So we have to provide the same password again. After that we will get a message with “passwd: all authentication tokens updated successfully.”
After we get this message we are ready to reboot the system again with a new root password. But before reboot we need to exit from the chroot permission. So run the exit command.
#exit
#reboot
Once the system is rebooted then put the user root and try the new password.
This whole process needs to be done physically on the system. Remote access does not work on this procedure. So we need to keep in mind that whenever we put a physical system we should cover that area with proper surveillance.