How do you recover a root password on a debian system
I know some people might think this is not the information that should be publicly published - but it is important to know and, if we are not encrypting our filesystems, we should acknowledge that if someone has physical access to your machine, then it can belong to them.
So having said that…
I’m assuming you are running Grub and I’m assuming that your root partition is not encrypted.
Once Grub boots, select the kernel that you want and press e to edit it.
Then scroll to the line with the kernel on it and click e again.
Then, at the end of that line, add:
This says: after loading the kernel, directly enter a bash shell.
Then hit enter.
Then hit the b key to boot.
After the kernel boots, you should get a bash prompt. At this point, your root partition is mounted read-only - so you won’t be able to change the password on it until you make it read-write.
mount -orw,remount /
This means don’t try to mount the root partition, instead remount it with the new option: rw.
Then, change the password with:
Now, your password has been saved. Now - remount the file system as read-only:
mount -oro,remount /
Now you are back to where we started before the password change.
This means replace the current process with “init” - and that is what the kernel does by default (before we changed it to init=/bin/sh) - so the system should now boot normally.