Difference between revisions of "Lost Password"

From FreekiWiki
Jump to navigation Jump to search
(→‎Ubuntu 12.04: fixed a minor typo)
Line 34: Line 34:
 
To mount the file system in read/write mode, type in the following command at the prompt;
 
To mount the file system in read/write mode, type in the following command at the prompt;
  
   mount -o,remount,rw /
+
   mount -o remount,rw /
  
 
===Resetting the Password===
 
===Resetting the Password===

Revision as of 13:53, 28 December 2013

The following applies to most linux boxen. It can be used to recover a lost password and is also called "rooting" the box.

Booting into Single User Mode with GRUB

Ubuntu 10.04

  1. start the computer booting up, and hold down the right shift key.
  2. After a few (or 10 or 20) seconds you will see the grub menu, which is characterized by a lines that will say ...kernel 2.6...
  3. Hit the down arrow once to get to a line that ends with recovery mode and press enter.
  4. This will bring up a menu with many options.

The two that you're looking for are netroot and root.

  1. Selecting "Netroot" will set up networking and mount the file system in read write mode (which is needed for making changes), and then drop you to a root shell.
  2. Selecting"Root" will just drop you to a root shell without the file system being mounted in read write mode.

After selecting "netroot", you will be see a line at the bottom of the screen that should say

  root@freekbox:~#

Proceed to "Resetting the Password" section of this page.

Ubuntu 12.04

  1. start the computer, immediately after the BIOS information has passed, press and hold down the left shift key.
  2. After a few seconds (maybe as much as 10 seconds), you will see the grub menu, which is characterized by a lines that will say ...kernel 3.2...
  3. Hit the down arrow key until it arrives on a line that ends with recovery mode and press enter.
  4. This will bring up a menu with many options.

Look for the menu entry that says Root

  1. Selecting"Root" will drop you to a root shell without the file system being mounted in read/write mode.

After selecting "Root", you will see a line at the bottom of the screen that should say

  root@freekbox:~#

To mount the file system in read/write mode, type in the following command at the prompt;

  mount -o remount,rw /

Resetting the Password

  1. at the root prompt, enter
 passwd yourusername 

replace 'yourusername' with the username you're trying to reset, or 'oem' if it has not been changed

If you are unsure of the users name, enter the following command;

 ls /home 

This will show all the users that have a folder in the /home directory. The names listed here are the user names.

  1. It will request that you enter a new password, and then once more to confirm. The screen will not show input as you are typing.
  2. Once the new password has been entered correctly, you will receive a message indicating that; passwd: password updated successfully Please take note of the password and store it in a safe place.
  3. type reboot to restart the computer.


  1. Alternatively type startx and you will be put in a graphical environment where you can use the normal tools.

Shadow Folder Method

There are two methods to do this. One which will create a one-time use password for their account which then blanks the password on subsequent logins, and another which will permanently reset their password until you reset it. If the Shorter Way doesn't work, use the Longer Way. Remember to reset their password when you are done!

Also note that if they have a Root Password set you will need to use the #Live CD Method to reset it.

The Shorter Way

This method temporarily replaces the /etc/shadow directory and allows you to reset their password so you can login.

  1. Login via Terminal (alt-ctrl-F2 from GUI login, OR drop into Root Shell via Recovery Mode).
  2. Run :
cp /etc/shadow /etc/shadow.bak.(ISO DATE)

This copies the contents of the Shadow directory to a new directory for backup later. .bak simply reminds you it's a backup, and the ISO Format preserves the date. ISO = Year Month Day. September 24th, 2011 = 20110924.

  1. Run :
passwd (username) -e

This will reset the password of the defined username. The "-e" modifier will expire the defined password after one use. This will result in there being NO password for that account after the defined password expires. Note that this must be run as root. If you have not logged in via root shell you will need to use this code instead :

sudo passwd (username) -e
  1. Set their password to "freegeek".
  2. Reboot. Their password should have successfully been reset. If you still want to confirm their password has been reset, please follow #Restoring Their Old Shadow Directory.

The Longer Way

This method temporarily replaces the /etc/shadow directory and allows you to reset their password so you can login.

  1. Login via Terminal (alt-ctrl-F2 from GUI login, OR drop into Root Shell via Recovery Mode).
  2. Run :
cp /etc/shadow /etc/shadow.bak.(ISO DATE)

This copies the contents of the Shadow directory to a new directory for backup later. .bak simply reminds you it's a backup, and the ISO Format preserves the date. ISO = Year Month Day. September 24th, 2011 = 20110924.

  1. Run :
passwd (username)

This will prompt for a new password for the designated user name (you can determine their user name from the "whoami" command).

  1. Set their password to "freegeek".
  2. Reboot. Their password should have successfully been reset. You still must reset their password! #Restoring Their Old Shadow Directory.

Restoring Their Old Shadow Directory

  1. Login via Terminal (alt-ctrl-F2 from GUI login, OR drop into Root Shell via Recovery Mode).
  2. Run :
cp /etc/shadow.bak.[ISO DATE] /etc/shadow

This copies the contents of the backed up Shadow directory to the current Shadow Directory. You may need to verify the correct name of the backup by looking in the /etc directory.

  1. Reboot

Live CD method

If the box does not use grub to boot, one can boot the box using a live cd or a System Rescue CD (download one here), then login as root (not necessary with System rescue CD) and proceed by entering the following commands one by one (hit enter after each line).

mount /dev/sda1 /mnt
chroot /mnt
passwd username    (replace username with the username you're trying to reset, or "oem" if it has not been changed.
sync
reboot

To find your username you can use ls /home

For Macs

For Mac computers at the yaboot prompt enter:

Linux rw init=/bin/bash

Once you get to the # prompt you will need to reset the terminal

reset

Now check the username

ls /home

and reset the users password

passwd usernamehere

Reset root password

  1. start the computer booting up
  2. After a few (or 10 or 20) seconds you will see a screen that says... Grub Loading...3..2..1.
  3. During this screen, quickly press Esc, to go to the grub menu
  4. Next you will see several lines that start with Ubuntu, kernel 2.6..., this is the GRUB menu.
  5. Select the first line in the list and press 'e'
  6. You should see something along the lines of
root   (hd0,0)
kernel /boot/vmlinuz-2.6.24-27-generic root=UUID=3deb56... ro quiet splash
initrd /boot/initrd.imb-2.6.24-27-generic
quiet
  1. Select the second line and press 'e' again.
  2. Remove 'ro quiet splash' from the end of the line and add 'rw init=/bin/bash'. Hit enter.
  3. Press 'b'. The box will now boot up and you will get a prompt that says 'root@(none):/#'
  4. At the prompt enter
/usr/sbin/usermod -p '!' root

Restart the computer.

Reset Root password CD version

This method involves editing /etc/shadow by hand to get rid of the password.

  1. start the computer and insert the system rescue CD for the password reset.
  2. mount the directory by typing mount /dev/sda1 /mnt
  3. edit /mnt/etc/shadow with vi
  4. remove everything between the first and second colons (:) and replace it with ! (exclaimation mark)
  5. reboot the tower and remove the system rescue cd