"root" is the super user of Linux Operating System and he has full privilege to do anything on it. and if you forgot the root users password then it is very helpless situation for you. in this situation you will not able to do any changes in Linux Operating system, and as a standard user you do not have such privilege who has root user. but do not vary about this problem, Linux operating system has solution for this problem.
Before do this you need some basic concept about "init" process. init is father of all Linux processes and it is first process which is executed at the time of booting after the loading Linux kernel in to the RAM. By default init has 7 run levels and every run level has specific use.
Default runlevel. The runlevels used by Linux are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
This run levels you can change by 3 different ways in Linux Operating System
- In first method you can change run level from init configuration (/etc/inittab) file it will be permanent,
- In Second method run levels can change from Linux command prompt,
- You can also change run level temporary at the booting time.
For recover root password you will use third method change run level while booting. Step by step procedure describe below
Step - 1. Boot you which root Linux and grub boot loader screen will appear press "Enter" key and you will be in following screen, and hear type "e" to go in to edit mode.
Step - 2. In the edit windows select line which start from "kernel" and again press "e" to edit this line.
Step - 3. Now you are in Line editing mode and curser will be at end of the kernel line, at the end of line first press "space bar" and then type "1" and press "Enter" and then press "b" to boot the Linux with the new setting. and boot will start.
Step - 4. Wow see what happed you are in shall prompt without username and password, this is magic of Single user mode in Single user mode Linux never ask for username password to enter in to Linux system.
Step -5. Now at shall prompt type "passwd" command to change root password and for change password system will not ask for previous password, hear type new password and retype same password and you root password is changed reboot you Linux and login as a root with the new password and enjoy it.
Warning - In our world every thing has good side as well as bad side also. Linux Signal user mode also has bad side if anybody has physical accesses on you system so he can use single user mode to change root password, so you need to secure you systems single user mode for this two sequence of methods
- Protect your system with Bios Password.
- And use grub password to protect the grub editing mode while booting