WELCOME

2009年4月24日 星期五

How do I reset my root password?

Lost your root password?

If you have lost your root password, you can't really recover it, but you can change it if you have physical access to the machine.

The two most used methods of changing your root password if it's lost is:

  • Booting into single-user mode and resetting the password
  • Booting from a live CD and gain access to your installed system

Changing your root password by booting into single user mode:

Step 1: Reset your computer

Step 2: Boot into single user mode

Note: This will not work on high-security systems where GRUB or LILO is password protected. (You could use a bootable GRUB floppy to do this, though - and can anyone say "backdoor BIOS passwords" ;-)

Note: On debian-like systems, even single user mode prompts for a root password - see the Debian variations section below.

Booting into single user mode depends on the boot manager you're using.

To boot into single user mode using GRUB:

1. You might have to press  to see your boot menu (you will see a prompt)
2. Choose the kernel you want to boot using the arrow buttons on your keyboard
3. Press "e" for edit
4. Press the "end" button on your keyboard, type in a comma space ", " and then type "single"
5. Press and than "b" to boot that kernel, this will take you into single user mode

To boot into single user mode using LILO:

1. You might have to hold in the "shift" key to see the lilo: prompt (depending on your setup)
2. Type your kernel name, followed by "1" (for runlevel 1), a typical example would be:
lilo: linux 1

Step 3: Change your root password

Once you get to the command line prompt, type:

# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

You can then reboot and use your new root password

Debian variations

  • Instead of adding " single" or " 1" to your kernel command line, add " init=/bin/bash"
  • When it boots up, mount your root filesystem read-write:
# mount / -o remount,rw
  • Change the password:
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
  • Unmount and reboot
# mount / -o remount,ro
# sync
# reboot

Changing your root password from bootable media

Step 1: Boot into another Linux system

This can be any other Linux system on your computer. It can be another installed distribution, or a live CD such as RIP (Recovery is Possible) or Knoppix.

Step 2: Open a terminal

If you have booted into a system such as Knoppix or the Ubuntu Live CD, you will need to open a terminal first. Alternatively, you can switch to a virtual terminal by pressing CTRL+ALT+F2. You will need root access on this system to gain access to your system.

Step 3: Mount your root filesystem to be rescued

This will be the filesystem that contains your /bin, /etc and /sbin directories, typically /dev/sda1 or /dev/hda1.

Typing the following can give you a list of partitions with sizes, this might give you a clue as to which partition your root partition is:

#cat /proc/partitions

To mount your root partition, type:

#mount /dev/hda1 /mnt

To gain access to your system, type:

#chroot /mnt

You will now have full access to your old system. To change your root password, type:

# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

To exit from the chroot, type 'exit'. You can now reboot (by typing 'reboot' and to press enter') and gain root access to your system again.

Changing the root password with sudo

If you are using a system like Ubuntu, where the first user installed has sudo rights, or if you have sudo configured for one of your users, then you can change your root password using sudo:

jonathan@ubuntu$ sudo passwd root
Password:

(enter your user password here, not root's)

Enter new UNIX password:

(enter and re-enter your new root password here)

沒有留言:

張貼留言