There are a couple of ways in which you can change the root password of a linux system, if you have forgotten it.
The efficacious and fast way of doing this is:-
1.Getting the shell in read write mode :-
- At the lilo prompt type " linux init=/bin/bash rw " without the quotes . Now what this does is, it gives us the bash shell (Bourne again shell) in read write mode and does not start with /sbin/init , /etc/rc.d/* and rc.local and so on and so forth routines.
- Now use the passwd command and type the new password for root but you should not restart the system yet as it can cause data crash.
- After you have changed the password, remount the partition in read only mode, this can be done by using the command " mount -o remount,ro / " without the quotes.
- Now you can reboot manually without the risk of loosing the data as the partition is in read only mode
The other way of doing it is also efficacious but it does take a step more and is really a oaf thing to do if you know the first way.
2. Getting the shell in read mode :-
- At the lilo prompt type "linux init=/bin/bash" . This does that same but gives us the bash shell in read mode.
- But we want it in read-write mode so that the changes can be written to the /etc/passwd and /etc/shadow file. So for that execute the command " mount -o remount,rw / " (without the quotes). This remounts the /(root partition) in read write mode.
- Now you can follow the steps 2 to 4 in the aforementioned solution for accomplishing the task.
The last and most dreaded way:-
3. Running the system at init runlevel 1:- This should be done with complete caution because even if you misplace a single letter or white-space while editing the kernel line in the boot menu, the system would give you the error that it cannot find the kernel and if you still want to follow this method then do so with utmost caution.
Note:Almost all the system administrators password protect the boot menu but in case it is not password protected then you can easily change the root password.
Just follow these steps:-
- If you are using a dual boot system, then you would be using Grub boot loader and at the start-up you would be given the time to select which os you want to boot to. Interrupt the normal boot process by pressing any key (except enter of course) and select the linux partition and press e (for editing the Grub boot option).
- The boot commands will be displayed to you, Select the command representing the linux kernel from the list. The line would be of the form "kernel /vmlinuz-...." and press e again to edit this line.
- Be careful in this step, for changing the boot process to init run-level 1 , type the space followed by 1 at the end of the line (after the /rhgb). This tells the system to run only the scripts of run-level 1 ie rc1.d (remember we by passed this in the first 2 solutions). Now just press b to continue the boot process which will leave you with a bare shell with #prompt.
- Type the passwd command, you will be asked to enter the new root password and after you confirm it, reboot the system.
- Now you can log into the system with the new root password that you entered in the previous step.
This entry was posted
on Monday, July 6, 2009
at Monday, July 06, 2009
and is filed under
Unix/Linux
. You can follow any responses to this entry through the
comments feed
.
