Main menu

My Blog

Ubuntu – Lost Password

Let me guess… you lost your password? ehh , don’t worry the net is full of different solutions to the matter of this possible problem. First let me start by saying that this tutorial is not intended to retrive your original password (see my Cryptography section for that). Also if you have an encrypted home directory (like with TrueCrypt) this method won’t work.

There are several ways to reset your password. I will describe here 2 methods:
Method # 1 – No live cd
Method # 2 – With live cd

1- Boot the computer from an USB or CD ubuntu image. At the boot screen select “Try out”UBUNTU”

2- After the desktop session has loaded start the terminal or just press CTRL+ALT+t

3- At the terminal type:

sudo su
mkdir /mnt/new
fdisk -l
(now here is the hard part; you have to figure out what is the partition you need to use in the next comand, usually it's the one that hase the "*" on the line, check my screen shoot for help)
mount /dev/PARTITION /mnt/new
chroot /mnt/new
mount -o rw,remount /
passwd USERNAME
PASSWORD
PASSWORD

Let’s say you you don’t want to use the previous methods, anothe way to reset you password is to access and edit directly the shadow file of your filesystem located in /etc/shadow. I will not explain here how to mount the partition, what kind of priviledges you should have etc.. because there are multiple ways to access the linux partition, from a MacOSX, Windows, another linux distribution and so on.. but instead I will focus on how to edit the hash file properly in order to give you access to your user’s login.
here we go:
1- navigate into the /etc folder . There are sever files here, using a text editor open the one named “shadow”.
2- find the line containing your username. It should be something like this:

4- save and reboot the linux system. Login with your username and at the request to enter a password simply press enter (leave it empty).

Note this methode may not work on all distributions. I noticed that Ubuntu work only with the empty method (::) where instead other ditros may accept also (:!:) and (:NP:) inputs. They all say the same thing, which is that the user does not have a password.

Post navigation

3 responses to “Ubuntu – Lost Password”

I will shortly also include a way to restore the password without the use of the root “/” of the system but by directly editing the shadow password file, of the system. This method is usefull if you cannot chroot the system, for example if you don’t have a live-cd, and your grub is not installed (or password protected). This is required if you are trying to reset the password of a linux system by mounting it into a no linux system (mac-OSX, windows,..).