Hack 66 Reset Linux Passwords 
Use Knoppix to reset forgotten Linux passwords.
If you have forgotten a
user's password under Linux and you have root
access, you don't usually need a rescue disk because
you can reset the password with the root account. Even if you have
forgotten the root password, most Linux distributions let you log in
to single-user mode (add the single or
init=1 argument to the kernel at the boot prompt)
and change the password from the root account.
A paranoid system administrator might password-protect or disable
single-user mode altogether in /etc/inittab, but
you can still get to a root prompt to reset the password if you pass
init=/bin/sh to the kernel when you boot. However,
if the boot loader itself is password-protected and you forgot the
password, you must have some sort of rescue disk to reset the
password both in the boot loader (reference [Hack #2] or [Hack #53] for steps to
reconfigure the boot loader) and in the
/etc/passwd file.
It is simple to reset a password in Linux, and to reset a password
with Knoppix requires just one extra step. Boot the Knoppix CD and
mount your Linux system with read/write permissions:
knoppix@ttyp0[knoppix]$ sudo mount -o rw /dev/hda1
/mnt/hda1
Replace hda1 with your root partition. Now
run passwd under chroot, so
that the passwd command changes the root
password for the mounted system, and not Knoppix:
knoppix@ttyp0[knoppix]$ sudo chroot /mnt/hda1 passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
knoppix@ttyp0[knoppix]$
To change the password for a user instead or root, invoke the same
command but add the name of the user to the end:
knoppix@ttyp0[knoppix]$ sudo chroot /mnt/hda1 passwd username
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
knoppix@ttyp0[knoppix]$
With the password set to a new value, reboot and get back into your
system.
|