Linux Desktop Password Reset

Hacking stuff is usually pretty trivial. As long as you’ve got physical access that is. And here I’ll instruct you on how to reset passwords on a Linux installation. Either by booting a live ISO. Or by plugging the drive with the installation you’d like to reset some password(s) on into another Linux machine.

Realistically, repairing a broken installation is pretty similar. Although be aware that setting up the chroot may require additional steps. And actually fixing it would be harder than just running passwd in chroot on the installation.

Setup

For passwd we don’t need any fancy setup, we just need the rootfs mounted, chroot into it and run passwd. Run “lsblk” to identify the disk you’ll need to mount. Then mount it to /mnt. Some distros have software that can mount drives automatically to some media folder. This is fine for passwd, but for system repair operations you’d want to unmount that if it happens and do the whole setup manually.

For a system repair chroot setup use these additional mounts to make sure tools interacting with the system work. Assuming you mounted the rootfs and potentially the boot/EFI partition to /boot or /boot/efi.

1
2
3
4
5
mount -R /dev /mnt/dev
mount --make-rslave /mnt/dev
mount -t proc proc /mnt/proc
mount -t sysfs sysfs /mnt/sys
mount -t tmpfs tmpfs /mnt/run

The options -R and -t for mount are short hands for --rbind and --types respectively.

NOTE: if you’re reinstalling an UEFI boot manager you’ll likely need a mount -t efivarfs efivarfs /mnt/sys/firmware/efi/efivars too.

Fixing

For doing the password reset or other operations on the installation other than simple file edits, you just chroot into the installation.

1
chroot /mnt /bin/bash

You may also specify a new shell or one command with options to run in the new root after the path of the root. Also --groups with group names and --userspec with names or IDs of the main user and group to use during the chroot. Usually you’d want to just chroot using the root user. And to all the stuff you need to.

Like the password reset!

1
passwd

And then exit the chroot shell and proceed with the cleanup before rebooting into the fixed installation.

1
exit

Cleanup

Run “umount --recursive” on the rootfs mount point as root.

1
umount -R /mnt