Resetting Linux server passwords
Linux Password Recovery Guide (Proxmox/Live ISO)
This document provides a "surgical" method to regain access to a Linux VM by booting from a Live ISO and using a chroot (Change Root) environment to modify the internal user database.
Phase 1: Proxmox Configuration
- Attach ISO: In Proxmox, go to Hardware > CD/DVD Drive and select an Ubuntu or NixOS Live ISO.
- Set Boot Order: Go to Options > Boot Order and move the CD/DVD drive to the top.
- Boot: Start the VM and enter the "Live" environment (e.g., "Try Ubuntu").
Phase 2: Traditional Linux (Ubuntu, Debian, etc.)
Follow these steps for any standard Linux distribution.
1. Identify & Mount the Filesystem
Find your root partition (look for the largest "Linux" partition) and mount it:
sudo fdisk -l
sudo mount /dev/sda2 /mnt
2. Bind Virtual Filesystems
You must bridge the Live ISO's "nervous system" to your hard drive so the system can talk to the hardware.
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
Note: If you mounted your disk to a subfolder (e.g.,
/mnt/oldhdd), ensure the loop reflects that path:... /mnt/oldhdd$i; done.
3. Enter Chroot and Reset
sudo chroot /mnt
passwd <username>
Phase 3: NixOS (The "Nix Way")
NixOS handles chrooting differently because its binaries are stored in the /nix/store rather than standard locations.
- Mount the Disk:
sudo mount /dev/sda2 /mnt. - Enter System: Use the specialized tool:
sudo nixos-enter. - Reset: Run
passwd <username>.
- Warning: If your
configuration.nixhasusers.mutableUsers = false, this change will be overwritten on the next reboot. In that case, you must edit/mnt/etc/nixos/configuration.nixand set ahashedPassword.
Phase 4: Identifying "Hidden" Users
If the name on the login screen (GDM) doesn't match what you see in /home, follow these steps inside the chroot:
- Find Real Usernames: GDM shows "Display Names," but
passwdrequires the "Internal Username."
cut -d: -f1,5 /etc/passwd
-
Column 1: Internal Username (use this with
passwd). -
Column 5: Display Name (what you see on the login screen).
-
Check Human Users: List all users with a UID of 1000 or higher:
awk -F: '$3 >= 1000 && $3 != 65534 {print $1}' /etc/passwd
Phase 5: Cleanup & Exit
To prevent filesystem corruption, unmount everything cleanly before restarting.
- Exit: Type
exit(to leave chroot/nixos-enter). - Unmount:
for i in /run /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
sudo umount /mnt
- Finalize: In Proxmox, revert the Boot Order so the Hard Disk is first, then reboot the VM.
Troubleshooting
- "Authentication token manipulation error": The disk is Read-Only. Fix:
mount -o remount,rw /. - "Mount point does not exist": Your
forloop path does not match where you mounted the disk. Double-check your/mntfolder name.