Posted by: aneeska on: June 16, 2009
It gives me the shivers!
The worst thing that could happen to a linux user is to forget the root password. The infallible method is to write it down. It’s simple but silly.
Is there a better way out?
Hell yes.
I will give you three ways to do it.
1. adding a “1″ to the kernel grub option
2. chroot into the drive
3. modifying /etc/passwd file
Like this:
Linux boots and drops you inbto root prompt. Use “passwd” to change the password.
But this is found to work only on Fedora. Before dropping to root shell, debian(lenny) and ubuntu(hardy) asks for root password!
Update:
In fedora you can make it behave the same as Ubuntu or Debian by adding this line to “/etc/inittab“
# what to do in single user mode
~~:S:wait:/sbin/sulogin
Thanks to jenny for this update
Like this:
Linux boots and drops you inbto root prompt. Use “passwd” to change the password.
But this is found to work only on Fedora. Before dropping to root shell, debian(lenny) and ubuntu(hardy) asks for root password!
For the less privileged, chrooting on the drive can be used for root password change. Here’s how to do it.
1. Find out the partition on which the OS is installed
HOWTO:
Launch a terminal and execute the command :
$ mount
In the output, find out where is “/” mounted
ex:
[pit@stop ~]$ mount
/dev/sda6 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
2. Insert LiveCD of any linux distro and boot into its live session
3. mount the partition
$ mount /dev/sda6 /mnt/sda6
note:
1. if /mnt/sda6 is not present, create the directory using “mkdir”
2. it is not necessary that the partition will be sda6. It would be sixth partition but it could become sdb6 or sdc6. It varies according to your situation.
4. “chroot” into the mount point
$ chroot /mnt/sda6
Now you are inside the filsystem of your linux.
5. Change the root password
$ passwd
You are done!
This is dirtier than the previous one. Steps to follow: (following the assumptions made in the method above)
1. Insert Live CD of any linux distro and boot into its live session
2. mount the partition
$ mount /dev/sda6 /mnt/sda6
3. Open up the file “etc/passwd”
$ vim /mnt/sda6etc/passwd
change this line
“root:x:0:0:root:/root:/bin/bash”
to
“root::0:0:root:/root:/bin/bash”
The second field indicates the presence of a password. So removing the ”x” tells the OS that the “root” user has no password.
4. Now boot the machine without the LiveCD and set your own password for root using “passwd” command.
Again you are done.
Its a nice product and demanding also. I have used Stellar Phoenix Linux Recovery Software which has very similar features.
June 16, 2009 at 4:21 PM
I noticed you put ubuntu in your tags.
By default, Ubuntu doesn’t have a root password, and you also do not need to modify the Grub entries to get into single-user mode. You just select recovery mode from the Grub menu and that logs you in as root so you can change user passwords.
June 16, 2009 at 4:46 PM
point noted. i must say recovery mode completely missed my mind. thanks for reminding me. i was concentrating more on applying the same method on different distros.