This is a generic how to, working for all Linux distributions, not only for Ubuntu or Debian or Centos etc etc.
I see a lot of howto’s what are based on the same “story”: boot in “single mode” and type passwd to change the password, but are some systems like Debian and probably others what doesn’t let you get in single mode if you don’t know the root password … so the single mode solution it will not work.
First I will describe you the single mode solution, because the start of this solution is very similar with the next solution what I will present you in the end.
-
How To change the root password in single mode
-
Restart the machine.
-
Press any key while GRUB menu is loading.
-
You will see the Grub Menu with you configured kernels.
-
Choose a good kernel (or the options what is starting your linux) and press e to edit it.
-
Now choose the line that begins with ‘kernel’. Press ‘e’ again to edit this line.
-
Now at the end of the line just add: single
-
Press Enter and after that press b to boot that kernel
-
Other way to change the linux root password
-
Follow the same steps as “single mode solution” but only until step 6.
-
Replace the step 6 with: Now at the end of the line just add: init=/bin/sh
-
Press Enter and after that press b to boot that kernel
-
Kernel will boot and it will stop in a shell
-
In this shell type: mount -o remount,rw /
-
Now type: passwd and change the password
-
Now type: sync to syncing disk (flush from memory to HDD).
-
After that remount the disk read only: mount -o remount,ro and reboot / Or Ctrl+Alt+Printscr+S, Ctrl+Alt+Printscr+U, Ctrl+Alt+Printscr+B if you have Magic Sysrq keys enable:)
What are MagicSysRq keys ?
Ctrl+Alt+Printscr+U – unmount the disk
Ctrl+Alt+Printscr+B – reboot