Linux Chroot your way out.

Him Her

VIP Member
VIP Member
Joined
Dec 23, 2011
Messages
8,145
Reaction score
6,435
Location
North Yorkshire
Simple things can be most irritating on any system and Linux is no exception. You forgot your password and now you can't get onto your system, oh well, just reinstall then? Nooooo!

You probably installed off a Live-CD so boot the system back up off the same CD and run up a console. The root filesystem that is now mounted is NOT the filesystem that you can't get access to, it's the CD. You need to know which partition on the hard disk is root. If you have just the one installed OS and you have SATA drives then it is most likely /dev/sda1 but you could:

sudo fdisk -l (lowercase L for list)

and check which partition has the asterisk (*) against it - that's the root filesystem

Mount this filesystem using

sudo mount /dev/sda1 /mnt (substitute your root filesystem for /dev/sda1)

The root filesystem of the installation you can't logon to (because you forgot the password) is now mounted under /mnt in full.

Make the inaccessible filesystem the target for future commands:

sudo chroot /mnt

Now, all you have to do is issue the passwd command against the username you forgot the password for:

sudo passwd username (use your own username here)

You'll be prompted to enter the password a second time for verification.

Reboot the system and voila you're in! Of course, you would only do this on your OWN system :whistle:

Use the same technique if you suspect the user files are corrupted i.e. you can logon but the system then doesn't work correctly. So, after using chroot to get to the bust filesystem, add a new user:

sudo useradd newuser
sudo passwd newuser


Don't forget to add the new user to the sudoers list or they won't be able to do anything!

sudo adduser newuser sudo

Now you have a new administrative user with a completely fresh profile.

Saves having to reinstall all the time :)
 
Back
Top