Difference between revisions of "Reset root password"

From ArchWiki
Jump to: navigation, search
(Method 3 - Using Another Linux Distro on Your System)
(Using a LiveCD)
(24 intermediate revisions by 9 users not shown)
Line 1: Line 1:
=Resetting Root Passwords=
+
[[Category:System recovery]]
Below are several methods one can use to reset the system's root password should it be forgotten or corruptedThe methods are the same in principal but differ in what is required to access them.  There are more ways to do this you can find in a google search too.
+
[[Category:Security]]
==Method 1 - Using the Arch Live CD==
+
[[it:Password Recovery]]
1. Boot the Arch Live CD and mount your root partition to <code>/mnt</code>.
+
[[ja:Password Recovery]]
 +
[[ru:Password Recovery]]
 +
[[zh-cn:Password Recovery]]
 +
This guide will show you how to recover a forgotten root password.  A several methods are available that can help you accomplish this.
  
2. Bind mount the <code>/dev</code>, <code>/sys</code>, and <code>/proc</code> special mount points into your <code>/mnt</code>:
+
== Using a LiveCD ==
  
  # mount --bind /dev /mnt/dev
+
With a LiveCD a couple methods are available: change root and use the {{Ic|passwd}} command, or erase the password field entry. Any Linux capable LiveCD can be used, albeit to change root it must match your installed architecture type.
# mount --bind /sys /mnt/sys
+
# mount --bind /proc /mnt/proc
+
  
3. <code>chroot</code> into your installation:
+
=== Change Root ===
  
# chroot /mnt /bin/bash
+
# Boot the LiveCD, and [[Change Root|change root]].
 +
# Use the {{Ic|passwd}} command to reset your root password.
 +
# Exit [[Change Root|change root]].
 +
# Reboot, and remember your password.
  
4. Use the <code>passwd</code> command to reset your root password.
+
=== Password Erase ===
5. Reboot and don't lose your password again!
+
  
==Method 2 - Using GRUB's Boot Menu==
+
1. Boot the LiveCD, and mount your root ('''/''') partition. For example:
1. Select the appropriate entry in the GRUB menu and press {{Keypress|e}} to edit the line.
+
  
2. Select the kernel ... line and press {{Keypress|e}} again to edit it.
+
mkdir /mnt/arch
 +
mount /dev/sda2 /mnt/arch
  
3. Append '''init=/bin/bash''' at the end of line.
+
2. Edit the password file with your editor. Example vim:
  
4. Press {{Keypress|b}} to boot (don't worry, this change is only temporary and will not be saved to your menu.lst).  Once you boot you should be at a (#) prompt.
+
vim /mnt/arch/etc/shadow
 +
 
 +
3. Delete the second field on the root line (in [[Vim|vim]] this can be done by going to the first letter/symbol in the field and typing '''d/:/''' then '''Enter'''):
 +
 
 +
root:'''$1$9gDquXRP$gbOHLXuqslL.rw81q4pHc1''':14589::::::
 +
 
 +
4. Save the file (''':x''' in vim).
 +
 
 +
5. Reboot and root login will not require a password.
 +
 
 +
== Using GRUB to Invoke Bash ==
 +
 
 +
1. Select the appropriate boot entry in the GRUB menu and press '''e''' to edit the line.
 +
 
 +
2. Select the kernel line and press '''e''' again to edit it.
 +
 
 +
3. Append {{Ic|1=init=/bin/bash}} at the end of line.
 +
 
 +
4. Press '''b''' to boot (this change is only temporary and will not be saved to your menu.lst).  After booting you will be at the bash prompt.
  
 
5. Your root file system should be mounted as readonly so remount it as read/write:
 
5. Your root file system should be mounted as readonly so remount it as read/write:
 +
 
  # mount -n -o remount,rw /
 
  # mount -n -o remount,rw /
  
6. Use the <code>passwd</code> command to reset your root password.
+
6. Use the {{Ic|passwd}} command to create a new root password.
 +
 
 +
7. Reboot and do not lose your password again!
 +
 
 +
{{Note|Some keyboards may not be loaded properly by the init system with this method and you will not be able to type anything at the bash prompt.  If this is the case, you will have to use another method.}}
  
7. Reboot and don't lose your password again!
+
== Resources ==
  
==Method 3 - Using Another Linux Distro on Your System==
+
* [http://www.howtoforge.com/how-to-reset-a-forgotten-root-password-with-knoppix-p2 this guide] for an example.
If you have another distro install on another partition, you can simply chroot into your "broken" partition from a shell and reset the password from there.  See [http://www.howtoforge.com/how-to-reset-a-forgotten-root-password-with-knoppix-p2 this guide] for an example.
+

Revision as of 04:59, 8 November 2012

This guide will show you how to recover a forgotten root password. A several methods are available that can help you accomplish this.

Using a LiveCD

With a LiveCD a couple methods are available: change root and use the passwd command, or erase the password field entry. Any Linux capable LiveCD can be used, albeit to change root it must match your installed architecture type.

Change Root

  1. Boot the LiveCD, and change root.
  2. Use the passwd command to reset your root password.
  3. Exit change root.
  4. Reboot, and remember your password.

Password Erase

1. Boot the LiveCD, and mount your root (/) partition. For example:

mkdir /mnt/arch
mount /dev/sda2 /mnt/arch

2. Edit the password file with your editor. Example vim:

vim /mnt/arch/etc/shadow

3. Delete the second field on the root line (in vim this can be done by going to the first letter/symbol in the field and typing d/:/ then Enter):

root:$1$9gDquXRP$gbOHLXuqslL.rw81q4pHc1:14589::::::

4. Save the file (:x in vim).

5. Reboot and root login will not require a password.

Using GRUB to Invoke Bash

1. Select the appropriate boot entry in the GRUB menu and press e to edit the line.

2. Select the kernel line and press e again to edit it.

3. Append init=/bin/bash at the end of line.

4. Press b to boot (this change is only temporary and will not be saved to your menu.lst). After booting you will be at the bash prompt.

5. Your root file system should be mounted as readonly so remount it as read/write:

# mount -n -o remount,rw /

6. Use the passwd command to create a new root password.

7. Reboot and do not lose your password again!

Note: Some keyboards may not be loaded properly by the init system with this method and you will not be able to type anything at the bash prompt. If this is the case, you will have to use another method.

Resources