Method One : Booting in single mode from GRUB or LILO:
Hey, but its asking me for root password to log into single-user mode?
Don’t worry…..
The same method will work if you have LILO as boot loader instead of GRUB.
Method Two : Using Boot disk or Live CD....
In this method, you need a Linux boot disk or a rescue disk. (If you didn't create one when prompted during the installation then let this be a lesson for you.) You can use your installation CD as a rescue disk; most distros have an option to allow you to boot into rescue mode.
Boot from Red hat Linux CD, at command prompt type “linux rescue” (without the quotes) to start the rescue mode. This will drop you in the root bash prompt in Single User Mode.
If you using a Live CD like Knoppix or Gnoppix then boot the live cd as normal & once system finishes booting, press
# mkdir /mnt/hd
# mount /dev/hdaX /mnt/hd
(where /dev/hdaX is your Linux system partition with forgotten root password, it could be /dev/hda1 if you IDE hard disk or /dev/sdaX if you have a S-ATA drive).
Once this command completed you can use passwd to set new root password.
# passwd
If chroot is not working for some reason then change to the "/etc" directory on your root partition by typing cd
# cd /mnt/hd/etc
# vi shadow
or
# vi passwd
(ESC) :wq
# cd /
# umount /mnt/hd
Method Three : Mounting your hard disk on another Linux system.....
Ah…I don’t know why you want to use this method…any way this is also sure to work
Do you think Linux doesn't have any security and you are very security-consious...here are various way to preventing others from resetting the root password....
Once the boot loader has been password protected, you won't be able to edit the kernel boot options (add single to the kernel line) unless you enter the boot loader password. However, you will be able to select what kernel to boot.
GRUB:
# /sbin/grub-md5-crypt
- Enter the password you want to set for GRUB. The MD5 hash will appear. Copy this hash line.
# vi /boot/grub/grub.conf and add the line under the timeout=5:
password --md5 passwordHASH
- Replace passwordHASH with the hash resulted from grub-md5-crypt. Simply paste here.
- It will look like this:
timeout=5
password --md5 $1$1OBii1$x78zK/tZB.VMoXzEzcg7x.
- Save the file and exit. Next time you reboot, you will have to press P and enter the password entered in order to edit the kernel boot options.
LILO:
- # vi /etc/lilo.conf
- Add the following line before the first image stanza:
password=NewPassword where NewPassword is the password you want to set for LILO.
- # /sbin/lilo -v This will let the changes take effect
- # chmod 600 /etc/lilo.conf This will allow only root to read and edit the file, since the password is in plain text.
Thats it.
If you want me write some method to preventing someone from removing the hard drive, mount it on another server and edit the /etc files & blah blah …......, then forget it.
Get a good lock from market, locked you cabinet. :)
Labels: change root password