How To Reset A Forgotten Root Password With Knoppix

摘自: www.howtoforge.com  被阅读次数: 58


yangyi 于 2008-05-13 19:13:41 提供


Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 02/26/2008

This guide explains how you can reset a forgotten root password with the help of the Knoppix Linux Live-CD. Afterwards you can log in to your system as root again.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

The method I'm describing here works only on systems to which you have physical access. If your server is in a remote datacenter, for example, you can't boot it from the Knoppix CD, but most hosters provide a rescue system that you can use in the same way to reset your password.

 

2 Using The Knoppix Live-CD To Reset The Root Password

Download the latest version of the Knoppix Live-CD and boot your system from it. Press ENTER at the boot prompt:

The Koppix system is starting:

After Knoppix has finished booting, you see the Knoppix desktop:

Open a terminal by clicking on the console icon:

Become root by typing:

su

To find out how your hard disk is partitioned, run

fdisk -l

In this case all files are in one partition, /dev/sda1. This partition contains the /etc/passwd and /etc/shadow files of the system for which we want to reset the root password; it also contains the passwd command. If you have more than one partition, you'll need all partitions in a moment that contain /etc/passwd, /etc/shadow, the passwd command and all files on which the passwd command depends.

To see if /dev/sda1 is already mounted, run

mount

As you see from the mount output, it's not mounted, but (as you can find out by running

ls -l /mnt

and

ls -l /media/sda1

) Knoppix has already prepared the directory /media/sda1 into which we can mount /dev/sda1. We do this now by running:

mount /dev/sda1 /media/sda1

(You might have to adjust this command to your system, e.g. if you have to mount multiple partitions, or if your partitions have different names.)

Type

mount

again, and you should now find /dev/sda1 in the mount output, mounted on /media/sda1:

Run

ls -l /media/sda1

and you should see the files and directories from your root partition.

Now comes the crucial part: we jail ourselves into the /media/sda1 directory so that we cannot see anymore what's outside; we are pretending to be on the regular Linux system instead of on the Live-CD system; this is called chrooting, so the command is:

chroot /media/sda1/

So now that it feels as if we were running the regular Linux system instead of the Knoppix Live-CD, we can use the normal commands from the regular system; to modify or reset a password, this is the passwd command which we use like this:

passwd root

Type in a new password and confirm it - and please try to not forget it again!

Now we can leave our chroot jail:

exit

...and reboot the system:

reboot

Remove the Knoppix CD, press ENTER, and boot into your regular Linux system:

If all goes well, you should now be able to log in with your new root password:

 

3 Links

Original link: http://www.howtoforge.com/how-to...