Difference between revisions of "Lost Password"

From FreekiWiki
Jump to navigation Jump to search
 
(23 intermediate revisions by 8 users not shown)
Line 1: Line 1:
The following applies to most linux boxen.  It can be used to recover a lost [[root]] password and is also called "rooting" the box.  It can be used on an Ubuntu box (which has no root password) to recover the user password.
+
{{Migrated}}
  
Generally it is easiest if the adopter brings the box in, but alternatively you can walk the adopter through the following:
+
[https://docs.google.com/document/d/1BoeY2M321pI5HwZhBxd7Ny032MQvpYaNviInjHlGSm0/edit?usp=sharing]
Alternatively you can use the instructions [http://www.howtogeek.com/howto/linux/reset-your-forgotten-ubuntu-password-in-2-minutes-or-less/| here]
 
  
==GRUB method==
+
The following applies to most linux boxen.  It can be used to recover a lost password and is also called "rooting" the box.
Edit the grub boot commands.
 
  
#start the computer booting up
+
==Booting into Single User Mode with GRUB==
#After a few (or 10 or 20) seconds you will see a screen that says... '''Grub Loading...3..2..1'''.  
+
 
#During this screen, quickly press Esc, to go to the grub menu
+
 
#Next you will see several lines that start with '''Ubuntu, kernel 2.6...''', this is the GRUB menu. hit the down arrow key as soon as you see this menu, it should select an option that ends with "recovery mode".
+
===Ubuntu 10.04 ===
#Make sure that the recovery mode option is highlighted and press enter.
+
''Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.''
#This will bring up a menu with 4 options: resume, dpkg, root, and xfix
+
#Power on the computer (shut it down first or simply reboot if it is already running).
#select "root" from this menu.  If you get a message that says "Give root password for maintenance (or type Control-D to continue):" then you have a root password set. Enter the root password here or if you don't know the root password follow the instructions under [[Lost_Password#Reset root password|here]]
+
#When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
#You will be given a line at the bottom of the screen that should say root@freekbox:~#
+
#After a few seconds you will see the GRUB menu, which is characterized by a lines that will say '''...kernel 3.2...'''. If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
#at this prompt, enter "passwd yourusername" (replace yourusername with the username you're trying to reset, or "oem" if it has not been changed.
+
#Hit the down arrow key (usually only once) until it arrives on the first line that ends with '''recovery mode''' and press enter.
#:If you don't know the accounts username you can type "ls /home" for a list of all accounts on the computer.
+
#Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges.
#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.
+
#You should now see a prompt at the bottom of the screen that reads
#once you enter your new password it should tell you "passwd: password updated successfully"
+
 
#type exit to go back to the recovery menu, then select resume to continue booting.
+
  root@freekbox:~#
 +
 
 +
Proceed to "Resetting the Password" section of this page.
 +
 
 +
===Xubuntu 12.04 ===
 +
''Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.''
 +
#Power on the computer (shut it down first or simply reboot if it is already running).
 +
#When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
 +
#After a few seconds you will see the GRUB menu, which is characterized by a lines that will say '''...kernel 3.2...'''. If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
 +
#Hit the down arrow key (usually only once) until it arrives on the first line that ends with '''recovery mode''' and press enter.
 +
#Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges. Note that until further steps are completed your file system will be in "read only" mode and you will not be able to make any persistent changes to the system.
 +
#You should now see a prompt at the bottom of the screen that reads
 +
 
 +
  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===
 +
 
 +
To reset your password you need to be able to specify the username for which the password is to be changed. Note that the name displayed on your login screen may not be the same as your formal username, instead being a "friendly" name that you provided at some point. For example, if your name on the login screen reads something like "John Doe" then that is almost certainly the "friendly" name, while your formal username is likely to be something more like "jdoe".
 +
 
 +
If you're unsure what the exact username you need to add is, type the following command:
 +
  cat /etc/passwd
 +
A large list will appear, containing lines such as
 +
  root:x:0:0:root:/root:/bin/bash
 +
  bin:x:1:1:bin:/bin:/bin/false
 +
  jsmith:x:1000:100:John Smith:/home/jsmith:/bin/bash
 +
In that example the first two lines are system accounts, but the third line is a user account that could be granted sudo access, with the first word of it (jsmith) being the correct username. User accounts can be distinguished by the number after the second ":" being 1000 or greater, and they will usually be towards the bottom of the list. If the list is particularly long and you don't see anything that fits the criteria (often the case when the Guest account has been used a lot) you may need to scroll up the list by pressing Shift+PageUp. Press PageDown to return to the command prompt below the list.
 +
 
 +
 
 +
Once you have identified your username, enter the following command with your specific username substituted:
 +
  passwd yourusername
 +
 
 +
You will be prompted to enter a new password, then to enter the password a second time to confirm nothing was mistyped.
 +
 
 +
Once you've updated your password you can restart the system by entering the command
 +
reboot
 +
 
 +
After a few seconds your system will reboot. The recovery menu may display again briefly before the computer restarts but will continue to reboot without any input. If you are presented with the GRUB menu again while rebooting then simply press the Enter key to select the first item on the menu and normal startup will continue.
  
==live CD method==
+
==Temporary Password Change==
If the box does not use grub to boot, one can boot the box using a live cd, a rescue floppy, or a Toms Root Boot disk, then login as root and proceed as above.
 
  
#"mount /dev/hda3 /mnt"
+
Use a temporary password change to gain access to a specific user account for troubleshooting without permanently changing or removing the user's password.
#"chroot /mnt"
 
#"passwd"
 
#change password
 
#"sync"
 
#reboot
 
  
The procedure can be used for distributions other than the freekbox2 or 3, but you first need to determine the name of the root partition for the mount command.
+
Follow instructions above for [[Lost_Password#Booting_into_Single_User_Mode_with_GRUB]] to reach the root prompt in recovery mode, but do not reset the password yet.
  
==For Macs==
+
Enter the following command, substituting today's date (in a numeric format such as 20140128) for 'DATE'.
 +
cp /etc/shadow /etc/shadow.bak.DATE
 +
This creates a backup copy of the shadow file, which contains all user passwords in an encrypted format, for later restoration. The <code>.bak.DATE</code> are just to remind you that it's a backup created on that date.
  
For Mac computers at the yaboot prompt enter:
+
Continue following the password reset instructions at [[Lost_Password#Booting_into_Single_User_Mode_with_GRUB]] to set a new password for the account you need to access.
  
Linux rw init=/bin/bash
+
With the changed password you should now be able to complete whatever troubleshooting tasks are necessary.
  
Once you get to the # prompt you will need to reset the terminal
+
Once you are ready to restore the user's password you will need to reach the root prompt in recovery mode as previously instructed, then run the following command, substituting the previously entered date for 'DATE':
 +
cp /etc/shadow.bak.DATE /etc/shadow
  
  reset
+
Verify the backup shadow file was restored correctly by running the command
 +
  ls -la /etc/shadow
 +
Compare the output of that command to this:
 +
-rw-r----- 1 root shadow 1939 Oct 24 15:39 /etc/shadow
 +
Most of that information will vary from the example and can be disregarded, but make sure that the section that reads "<code>root shadow</code>" is correct, as that indicates which user and group owns the file and must be correct to be able to log in to the system normally. If that section reads something other than "<code>root shadow</code>" then run the following command:
 +
chown root:shadow /etc/shadow
 +
Re-run the <code>ls -la /etc/shadow</code> command and verify that the output now matches.
  
Now check the username
+
You should now be able to reboot the system and the user's password will be restored to whatever it was when the backup was created.
  
ls /home
+
==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 [http://www.sysresccd.org/Download 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).
  
and reset the users password
+
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
  
passwd usernamehere
+
To find your username you can use <code>ls /home</code>
  
 
==Reset root password==
 
==Reset root password==
Line 60: Line 106:
 
#You should see something along the lines of
 
#You should see something along the lines of
 
  root  (hd0,0)
 
  root  (hd0,0)
  kernel /boot/vmlinuz-2.6.24-27-generic root=UUID=3deb56...
+
  kernel /boot/vmlinuz-2.6.24-27-generic root=UUID=3deb56... ro quiet splash
 
  initrd /boot/initrd.imb-2.6.24-27-generic
 
  initrd /boot/initrd.imb-2.6.24-27-generic
 
  quiet
 
  quiet
Line 69: Line 115:
 
  /usr/sbin/usermod -p '!' root
 
  /usr/sbin/usermod -p '!' root
 
Restart the computer.
 
Restart the computer.
 +
 +
===Reset Root password CD version===
 +
This method involves editing /etc/shadow by hand to get rid of the password.
 +
 +
#start the computer and insert the system rescue CD for the password reset.
 +
#mount the directory by typing '''mount /dev/sda1 /mnt'''
 +
#edit '''/mnt/etc/shadow''' with vi
 +
#remove everything between the first and second colons (:) and replace it with ! (exclaimation mark)
 +
#reboot the tower and remove the system rescue cd
  
 
[[Category:Tech support]]
 
[[Category:Tech support]]

Latest revision as of 13:45, 9 May 2014

deletion

This page has been migrated to a document on Free Geek's Google Drive.

Information remaining behind may no longer be relevant.

MIGRATOR:

When you have tagged this page as migrated,
please add a link to the new document on Google Drive.

(Link to new page immediately below.)


[1]

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

Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.

  1. Power on the computer (shut it down first or simply reboot if it is already running).
  2. When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
  3. After a few seconds you will see the GRUB menu, which is characterized by a lines that will say ...kernel 3.2.... If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
  4. Hit the down arrow key (usually only once) until it arrives on the first line that ends with recovery mode and press enter.
  5. Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges.
  6. You should now see a prompt at the bottom of the screen that reads
  root@freekbox:~#

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

Xubuntu 12.04

Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.

  1. Power on the computer (shut it down first or simply reboot if it is already running).
  2. When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
  3. After a few seconds you will see the GRUB menu, which is characterized by a lines that will say ...kernel 3.2.... If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
  4. Hit the down arrow key (usually only once) until it arrives on the first line that ends with recovery mode and press enter.
  5. Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges. Note that until further steps are completed your file system will be in "read only" mode and you will not be able to make any persistent changes to the system.
  6. You should now see a prompt at the bottom of the screen that reads
  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

To reset your password you need to be able to specify the username for which the password is to be changed. Note that the name displayed on your login screen may not be the same as your formal username, instead being a "friendly" name that you provided at some point. For example, if your name on the login screen reads something like "John Doe" then that is almost certainly the "friendly" name, while your formal username is likely to be something more like "jdoe".

If you're unsure what the exact username you need to add is, type the following command:

  cat /etc/passwd

A large list will appear, containing lines such as

  root:x:0:0:root:/root:/bin/bash
  bin:x:1:1:bin:/bin:/bin/false
  jsmith:x:1000:100:John Smith:/home/jsmith:/bin/bash

In that example the first two lines are system accounts, but the third line is a user account that could be granted sudo access, with the first word of it (jsmith) being the correct username. User accounts can be distinguished by the number after the second ":" being 1000 or greater, and they will usually be towards the bottom of the list. If the list is particularly long and you don't see anything that fits the criteria (often the case when the Guest account has been used a lot) you may need to scroll up the list by pressing Shift+PageUp. Press PageDown to return to the command prompt below the list.


Once you have identified your username, enter the following command with your specific username substituted:

 passwd yourusername

You will be prompted to enter a new password, then to enter the password a second time to confirm nothing was mistyped.

Once you've updated your password you can restart the system by entering the command

reboot

After a few seconds your system will reboot. The recovery menu may display again briefly before the computer restarts but will continue to reboot without any input. If you are presented with the GRUB menu again while rebooting then simply press the Enter key to select the first item on the menu and normal startup will continue.

Temporary Password Change

Use a temporary password change to gain access to a specific user account for troubleshooting without permanently changing or removing the user's password.

Follow instructions above for Lost_Password#Booting_into_Single_User_Mode_with_GRUB to reach the root prompt in recovery mode, but do not reset the password yet.

Enter the following command, substituting today's date (in a numeric format such as 20140128) for 'DATE'.

cp /etc/shadow /etc/shadow.bak.DATE

This creates a backup copy of the shadow file, which contains all user passwords in an encrypted format, for later restoration. The .bak.DATE are just to remind you that it's a backup created on that date.

Continue following the password reset instructions at Lost_Password#Booting_into_Single_User_Mode_with_GRUB to set a new password for the account you need to access.

With the changed password you should now be able to complete whatever troubleshooting tasks are necessary.

Once you are ready to restore the user's password you will need to reach the root prompt in recovery mode as previously instructed, then run the following command, substituting the previously entered date for 'DATE':

cp /etc/shadow.bak.DATE /etc/shadow

Verify the backup shadow file was restored correctly by running the command

ls -la /etc/shadow

Compare the output of that command to this:

-rw-r----- 1 root shadow 1939 Oct 24 15:39 /etc/shadow

Most of that information will vary from the example and can be disregarded, but make sure that the section that reads "root shadow" is correct, as that indicates which user and group owns the file and must be correct to be able to log in to the system normally. If that section reads something other than "root shadow" then run the following command:

chown root:shadow /etc/shadow

Re-run the ls -la /etc/shadow command and verify that the output now matches.

You should now be able to reboot the system and the user's password will be restored to whatever it was when the backup was created.

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

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