Reset Root Password

First trick involves getting your root password back when you’ve lost it. Ever had that happen? It can be rather nerve-wracking. And if you try to reboot the box and bring it up into single-user, it may actually ask for your password before allowing you to get a shell. That simply won’t do.
It’s easy, though, if you have access to a serial console.

When you first boot a Linux box, the kernel goes through and does its kerneley things. Setting up drivers, sacrificing firstborns, all that neat stuff. But after it’s all done and ready to start stuff in userspace, it starts up a program called “init”, which is the alpha and the omega of all userspace programs. It is the father of every single program that you see in ps except for the virtual ones that the kernel spawns, such as ksoftirqd.

You can use this fact to completely subvert the entire bootup process to your own ends.
When your system comes up to the grub prompt, select “e” for edit. Then move your arrow to the “kernel” line, and select “e” again. This will let you edit the line.
Add the following to the end:
init=/bin/sh
And type “b” to boot. The kernel will boot, but instead of starting init, it will instead start a shell (you have basically fooled the kernel into thinking that /bin/sh is init).
Now run the following commands:
mount -o remount,rw /
mount /usr
sync sync
passwd roo
texit
The first command remounts the root filesystem as read-only (you’ll need this in order to make any changes). The second command gives you some other tools - most likely your favorite text editor. The third command changes the password, but the fourth and fifth commands are the most important. Since there are no system services running at all, the chances of your changes actually being synced back to the filesystem after making your change is actually pretty low. Running the first command causes it to happen. Running the second “sync” command forces you to wait enough time for the data to actually be flushed back to disk (these things don’t happen instantly).
The system will possibly panic on running exit. Don’t worry about this. Just reboot the system. You should be able to log in with your new root password.

0 comments:

Post a Comment