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

Name-codes used in this tutorial:


USERNAME = your username (ex. john, abby,..)
PASSWORD = your password (ex. pAsSwRd123)
PARTITION = your partition name (ex. sda1, sdb2, hda3,..)

Let’s get started!

———–Method # 1 – NO live cd————-

1- Start up the computer and at the grub menu select Recovery mode
If you do not see the grub menu press “SHIFT” key at boot time.screen2- From the recovery menu select ROOT console
screen23- At the prompt type:


root@tHOSTNAME:~#mount -o rw,remount /
root@tHOSTNAME:~#passwd USERNAME
Changing password for USERNAME.
Enter new UNIX PASSWORD:
Retype new UNIX PASSWORD:
passwd:password updated succesfully
reboot 0

-screenshoot-

meme

———————————————–
———–Method #2 – WITH live cd————-
———————————————–

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

screen2

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

-screenshoot-

screen

———————–Update——————————
———————————————————–
———–Method #3 – EDIT /etc/shadow FILE ————-
———————————————————–

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:


USERNAME:$6$XXtFftG.$K8fw0HOt5zRP5iowAqB/GSkku4MrUHYIUIUD4LCqJntS2UcU2XhMKBktVLmjGC3Kr.68PTmxO/CXOZqW7EZbPN1:15666:0:99999:7:::

what is this?
6 = hash method (SHA512)
XXtFftG. = salt
K8fw0HOt5zR....qW7EZbPN1= hashed password

3- change these line into this :


USERNAME::15666:0:99999:7:::

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.

Advertisements

3 responses to “Ubuntu – Lost Password

  1. 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,..).

    Update: Done!

  2. thank you, the last method was very helpfull. Could you also write something about windows 8 and MacOSX password reset?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s