Difference between revisions of "Reset root password"

From ArchWiki
Jump to: navigation, search
(update interlanguage links (https://github.com/lahwaacz/wiki-scripts/blob/master/update-interlanguage-links.py))
 
(25 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:System recovery]]
 
[[Category:System recovery]]
 
[[Category:Security]]
 
[[Category:Security]]
[[it:Password Recovery]]
+
[[ar:Reset root password]]
[[ru:Password Recovery]]
+
[[it:Reset root password]]
This guide will show you how to recover a forgotten root password. A several methods are available that can help you accomplish this.
+
[[ja:パスワードリカバリ]]
 +
[[ru:Reset root password]]
 +
[[zh-cn:Reset root password]]
 +
This guide will show you how to reset a forgotten root password. Several methods are listed to help you accomplish this.
 +
 
 +
{{Warning|An attacker could use the methods mentioned below to break into your system. No matter how secure the operating system is or how good passwords are, having physical access amounts to loading an alternate OS and exposing your data, unless you use [[disk encryption]].}}
  
 
== Using a LiveCD ==
 
== Using a LiveCD ==
  
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 much match your installed architecture type.
+
With a LiveCD a couple methods are available: change root and use the {{Ic|passwd}} command, or erase the password field entry directly editing the password file. Any Linux capable LiveCD can be used, albeit to change root it must match your installed architecture type. Here we only describe how to reset your password with chroot, since manual editing the password file is significantly more risky.
 
+
=== Change Root ===
+
 
+
# 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.
+
 
+
=== 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|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:
+
=== Change root ===
  
# mount -n -o remount,rw /
+
# Boot the LiveCD and [[mount]] the root partition of your main system.
 +
# Enter the [[chroot]] session.
 +
# Use the {{ic|passwd}} command to set the new password (you won't be prompted for an old one).
 +
# Exit chroot session.
 +
# Unmount the root partition.
 +
# Reboot, and enter your new password. If you can't remember it, go to step 1.
  
6. Use the {{Ic|passwd}} command to create a new root password.
+
== Using GRUB to invoke bash ==
  
7. Reboot and do not lose your password again!
+
# Select the appropriate boot entry in the GRUB menu and press {{ic|e}} to edit the line.
 +
# Select the kernel line and press {{ic|e}} again to edit it.
 +
# Append {{Ic|1=init=/bin/bash}} at the end of line.
 +
# Press {{ic|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.
 +
# Your root file system is mounted as readonly now, so remount it as read/write {{ic|mount -n -o remount,rw /}}.
 +
# Use the {{ic|passwd}} command to create a new root password.
 +
# 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.}}
+
{{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 ==
+
== See also ==
  
 
* [http://www.howtoforge.com/how-to-reset-a-forgotten-root-password-with-knoppix-p2 this guide] for an example.
 
* [http://www.howtoforge.com/how-to-reset-a-forgotten-root-password-with-knoppix-p2 this guide] for an example.

Latest revision as of 20:21, 2 September 2015

This guide will show you how to reset a forgotten root password. Several methods are listed to help you accomplish this.

Warning: An attacker could use the methods mentioned below to break into your system. No matter how secure the operating system is or how good passwords are, having physical access amounts to loading an alternate OS and exposing your data, unless you use disk encryption.

Using a LiveCD

With a LiveCD a couple methods are available: change root and use the passwd command, or erase the password field entry directly editing the password file. Any Linux capable LiveCD can be used, albeit to change root it must match your installed architecture type. Here we only describe how to reset your password with chroot, since manual editing the password file is significantly more risky.

Change root

  1. Boot the LiveCD and mount the root partition of your main system.
  2. Enter the chroot session.
  3. Use the passwd command to set the new password (you won't be prompted for an old one).
  4. Exit chroot session.
  5. Unmount the root partition.
  6. Reboot, and enter your new password. If you can't remember it, go to step 1.

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 is mounted as readonly now, 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.

See also