How to recover Ubuntu user password

0

A while ago I've installed Ubuntu as a second OS on my laptop, just to try out Linux. I have created one user & gave it admin privileges.

Haven't touched it for a while, and, of course, forgot the password. Tried all my commonly used passwords for that user and root, but they don't work.

Is there a way to recover passwords somehow?

flamey

Posted 2009-10-01T23:34:34.283

Reputation: 167

Answers

5

Copied and pasted from http://www.ubuntugeek.com/how-to-recover-password-under-ubuntu.html

Press ESC at the grub prompt.

Press e for edit.

Highlight the line that begins kernel ………, press e

Go to the very end of the line, add rw init=/bin/bash

press enter, then press b to boot your system.

Your system will boot up to a passwordless root shell.

Type in passwd username

Set your password.

Type in reboot

MDMarra

Posted 2009-10-01T23:34:34.283

Reputation: 19 580

I think that more recent versions of Ubuntu may block this method (it is a gaping security hole), but it's still worth a shot. – Telemachus – 2009-10-01T23:41:44.707

1Similarly, instead of "rw init=/bin/bash", the more traditional way is to say "single" to boot in single user mode. I think that still works on Ubuntu. – Paul Tomblin – 2009-10-01T23:42:03.957

I'm pretty sure that single user mode requires that you type in the root password. – wfaulk – 2009-10-01T23:43:32.830

@Telemachus: If you have access to the hardware, there's not really much anyone can do to keep you from the data. I suppose a completely encrypted filesystem might. – wfaulk – 2009-10-01T23:45:15.650

@Wfaulk: grub can easily be configured so that it requires a password in order to edit the boot line. I do this on my Debian installation, for exactly this reason. I think that Ubuntu might now do this by default, but I am not 100% sure of that. – Telemachus – 2009-10-02T00:01:05.867

single mode does prompt for root password, but there's a message that suggests Ctrl-D may allow accessing the system without a password anyway. (might just initiate a reboot.. not sure, i've never had to boot to single when i didn't know the password.) – quack quixote – 2009-10-02T00:08:04.997

@Telemachus: yeah, but you can always boot off of another CD. – wfaulk – 2009-10-02T00:32:03.567

@Wfaulk: Sure. I just wanted to warn the OP that the method Mark suggests may not work with Ubuntu, because I vaguely recall that method was blocked. I may completely wrong about that, but I never said anything about an airtight system. – Telemachus – 2009-10-02T00:37:14.513

1

Easiest way in general to recover a password under Linux is to boot from the install CD in recovery mode, mount the root filesystem at /mnt (or anywhere, really), and edit the /mnt/etc/passwd and /mnt/etc/shadow files to remove the password fields. Then unmount the root filesystem and reboot. Now you should be able to log in as that user with no password.

The "init=/bin/bash" suggestion above is very cool, though.

wfaulk

Posted 2009-10-01T23:34:34.283

Reputation: 5 692

You could also chroot into your mounted filesystem and use the passwd tool from there. (As root, or sudo'd, passwd won't ask for the current password before setting a new one.) – quack quixote – 2009-10-02T00:10:41.107