Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!

I loaded one of my test Ubuntu virtual machines today (one that I hadn’t used for a month) and, surprise, I had forgotten the password. This sort of thing happens from time to time, and if you’re new to Linux, it can be a little disconcerting.

Losing your root password isn’t the end of the world, though. You’ll just need to reboot into single user mode to reset it. Here’s how to do it on a typical Ubuntu machine with the GRUB bootloader:

Boot Linux into single-user mode

  1. Reboot the machine.
  2. Press the ESC key while GRUB is loading to enter the menu.
  3. If there is a ‘recovery mode’ option, select it and press ‘b’ to boot into single user mode.
  4. Otherwise, the default boot configuration should be selected. Press ‘e’ to edit it.
  5. Highlight the line that begins with ‘kernel’. Press ‘e’ again to edit this line.
  6. At the end of the line, add an additional parameter: ‘single’. Hit return to make the change and press ‘b’ to boot.

Change the admin password
The system should load into single user mode and you’ll be left at the command line automatically logged in as root. Type ‘passwd’ to change the root password or ‘passwd someuser’ to change the password for your “someuser” admin account.

Reboot
Once your done, give the three finger salute, or enter ‘reboot’ to restart into your machine’s normal configuration.

That’s all there is to it. Now just make sure to write your password down on a post-it and shove it somewhere safe like under your keyboard. :)


Related

Comments

  1. bachterman says:

    so this means i can change anyone’s password on ubuntu?
    i’m having concerns about security since the new google chrome bubble popped. :/

  2. paco says:

    … then its easy enough to “sudo passwd” to reset it. Or just live life in sudo, and “sudo su” when ever you need a terminal.

  3. kvn says:

    @bachterman

    It’s long been known that all bets are off if you have physical access. You could set a password on grub, but that doesn’t stop someone from booting a CD or removing the harddrive and mounting it. Next.

    @paco

    Yeah but ubuntu doesn’t typically have a root password.

  4. Seth says:

    You can use a capital “S” instead of “single” if you’re feeling lazy

  5. Jason Striegel says:

    @Ronny – Re:Loosing

    Oh, come on. To cast loose. To free from your control. To eject from your memory like a hot rocket of forgetfulness. Loosing your password.

    (I’ve corrected the post. Appropriate dose of shame has been applied.)

  6. Steve says:

    single user mode may still occasionally prompt you for a password.

    add init=/bin/bash to your kernel line to go straight to a bash prompt from bootup. You’ll probably have to remount your / partition as rw, and remember to sync after making any changes. You won’t be able to shut down nicely from this state, so ctrl + alt + del is the only option.

  7. Matthew Musgrove says:

    Actually this isn’t Ubuntu or Debian specific. It is a feature of the Linux kernel and has worked that way since at least 1995 but probably even a few years prior to that. Different bootloaders will have different methods to editing the kernel line though.

  8. CB says:

    If you give root a password, you’ll have to enter that password to boot into single user mode. Correct me if I’m wrong…..

  9. michelle says:

    I saw this on the google reader this morning and didn’t think much about it. JUST called the boyfriend who is moving into a new house and got an ear full about him forgetting his password…blah blah blah.

    I saved the day thanks to this little tip. More points for the slightly tech savvy girlfriend. Thanks!

  10. Rishav uprety says:

    this doesn’t work if the grub is password protected.
    Regards
    techspalace.blogspot.com

  11. mjc says:

    “If you’ve only forgotten the root password..

    … then its easy enough to “sudo passwd” to reset it. Or just live life in sudo, and “sudo su” when ever you need a terminal.”

    I’m pretty sure you need to enter the old password to reset it, so that doesn’t help if you’ve forgotten it.

  12. Robert says:

    You only have to enter the old password for non-root users, if you’re root you can, of course, just edit the /etc/passwd and /etc/shadow files directly. So passwd doesn’t ask for the old password.

  13. Mikko says:

    No box is secure if one can get a physical access to it. You should use a password to secure the bios (no booting from CD) and use a password to secure the GRUB.

    If you are allowed to boot from CD you can always change the root password.

    Greetings,

    mikko lightlinux.blogspot.com

  14. Isabelle says:

    Hallo!

    I have a four year old computer (Packard Bell) with Linux Debian and Gnome password manager. No one know the username and password. I do not want to uninstall Debian and Gnome because it´s folders with pictures on the computer. Before I uninstall everything I want to save the pictures if it´s possible. Is it possible. I am a really beginner with linux.

    Best regards
    Isabelle

  15. Isabelle says:

    Hallo!

    I have a four year old computer (Packard Bell) with Linux Debian and Gnome password manager. No one know the username and password. I do not want to uninstall Debian and Gnome because it´s folders with pictures on the computer. Before I uninstall everything I want to save the pictures if it´s possible. Is it possible. I am a really beginner with linux.

    Best regards
    Isabelle

  16. hackerharp says:

    Just open terminal and type in:passwd user, and then your done or do that using sudo.

  17. I’m running Ubuntu 13.10, after getting to # prompt, entering new password, twice, I get:
    ‘Authentication token manipulation error’
    the password was unchanged.
    What to do now?

    1. Michael says:

      You need to remount /, ‘mount -o remount,rw /’ before you can actually write to any files.

  18. Michael says:

    That’s why you pass the command ‘init=/bin/sh’ to the boot command.

  19. Michael says:

    @Solar Analytics

    You need to remount /, ‘mount -o remount,rw /’ before you can actually write to any files.