HOWTO - reset a lost Ubuntu password

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. :)

Posted by Jason Striegel | Sep 3, 2008 10:37 PM
Linux, Ubuntu | Permalink | Comments (16) Bookmark and Share

Recent Entries

Comments

Newest comments listed first.

Posted by: bachterman on September 4, 2008 at 12:00 AM

security

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


Posted by: paco on September 4, 2008 at 12:02 AM

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.


Posted by: Ronny on September 4, 2008 at 11:14 AM

"Loosing"?

N/C


Posted by: kvn on September 4, 2008 at 11:17 AM

Physical access

@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.


Posted by: Seth on September 4, 2008 at 12:07 PM

You can use a capital "S" instead of "single" if you're feeling lazy


Posted by: Jason Striegel on September 4, 2008 at 1:25 PM

Loosing

@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.)


Posted by: Steve on September 5, 2008 at 8:12 AM

init

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.



Posted by: Matthew Musgrove on September 5, 2008 at 8:52 AM

Actually...

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.


Posted by: CB on September 5, 2008 at 2:39 PM

Weellll.....

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.....


Posted by: michelle on September 5, 2008 at 3:17 PM

thanks

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!


Posted by: Rishav uprety on September 6, 2008 at 7:43 AM

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


Posted by: mjc on September 6, 2008 at 8:51 AM

"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.


Posted by: Robert on September 6, 2008 at 10:50 PM

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.


Posted by: Mikko on September 7, 2008 at 8:40 AM

no box is secure with physical access

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


Posted by: Isabelle on September 28, 2008 at 11:59 AM

Gnome password manager

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


Posted by: Isabelle on September 28, 2008 at 12:01 PM

Gnome password manager

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


Leave a comment



Bloggers

Welcome to the Hacks Blog!

Brian Jepson.Brian Jepson


Jason Striegel.Jason Striegel


Philip Torrone.Phillip Torrone



See all of the books in the Hacks Series!
Advertise here.

Recent Posts

www.flickr.com
photos in Hacks More photos in Hacks