14

I forgot my root password and am attempting to change it by booting into single-user mode, however when booting I get this screen:

enter image description here

Then I press "e" to edit the boot configuration and I get this screen:

enter image description here

However, in the tutorial I'm following it says I should navigate to the line that starts with "kernel", but as you can see, I dont have this line. So I tried changing "quiet" to "single" on the line that starts with "linux /boot/vmlinuz...." but this doesn't boots the system into single-user mode.

What line am I supposed to edit in order for this to work?

xorinzor
  • 269
  • 2
  • 4
  • 19

4 Answers4

22

DEBIAN / UBUNTU root PASSWORD RECOVERY

  1. First screen - grub - press e
  2. Modify kernel line: add single between ro quiet and at the end of this line add init=/bin/bash
  3. Press F10
  4. When the prompt is root@(none):/# you have to remount the / partition to have read-write access: mount / -rw -o remount
  5. Now you are ready to modify the root password: type passwd and change it!

Good luck

P.S: try to look at the /etc/shadow file to find other users...

HBruijn
  • 72,524
  • 21
  • 127
  • 192
user266991
  • 221
  • 2
  • 2
19

One method:

  1. Append init=/bin/bash to the end of the grub line which begins with linux (and ends with quiet).

  2. Reset your password and reboot normally.

  3. Don't forget it again.

  4. Consider installing sudo.


Another method:

  1. Since this is apparently a virtual machine, you can mount its disk on another (working) virtual machine and manually remove the password from the /etc/shadow file. Or use kpartx to work with the virtual machine image file from the host or from another machine.
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Now it shows me "root@(none)#" though and it doesn't know any commands, how do I fix that? – xorinzor Feb 24 '13 at 23:18
  • 2
    You probably don't have a `PATH`. Try calling `/usr/bin/passwd` (or anything else) directly. Or just look around and see what you have available to you. – Michael Hampton Feb 24 '13 at 23:19
  • 2
    using `/bin/bash` as init won't call any of the startup scripts to mount partitions, etc. either so if you have `/usr` in a separate partition you'll need to mount it by hand. Also know that you won't get the shutdown scripts either, when bash exits the kernel will immediately halt. Be sure to sync the drives first or changes may not be written. – DerfK Feb 25 '13 at 00:12
1

Your tutorial refers to Grub (legacy Grub). This is Grub2. The line beginning with linux would be the kernel line in Grub.

Hauke Laging
  • 5,157
  • 2
  • 23
  • 40
-1

wooo, just choose the recovery mode dude, you'll be switch to a BusyBox without any kind of password (normally).

Dr I
  • 943
  • 16
  • 33
  • Just tried it, also asks for a login after booting, during the boot I get the same maintenance question asking me for the root password or to press ctrl+D to continue – xorinzor Feb 24 '13 at 23:11
  • did you press Ctrl+D ? I already had such reaction on some linux tweaked box, and a Ctrl+D did the trick. – Dr I Feb 24 '13 at 23:14
  • yes I did, but then it just resumes like a normal boot and asks for the login – xorinzor Feb 24 '13 at 23:15
  • 1
    @DrI Debian's default is to require the root password for single user mode. – DerfK Feb 25 '13 at 00:14
  • Hum... are you sure?? I just installed a fresh Inet 6.0.6 version using default values for the setup and my single mode is NOT requiring any password. – Dr I Feb 25 '13 at 10:02
  • I tested with debian 9, recovery menu item without modifications DO require a root password. – Ashark Oct 05 '20 at 13:43