个人工具

UbuntuHelp:LostPassword

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月24日 (四) 16:23的版本 (新页面: {{From|https://help.ubuntu.com/community/LostPassword}} {{Languages|UbuntuHelp:LostPassword}} === Lost Password? === Sometimes it is necessary to get root access, for example when you h...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索


Lost Password?

Sometimes it is necessary to get root access, for example when you have forgotten your password or changed something in `/etc/sudoers` and things do not work as expected. This page lists three ways to reset your or someone else's password.

/!\ Be careful, each of the steps give you full root access to your system and you can really damage your system! Keep in mind that all the steps you see here can also be done by someone else!

Now let us start with a way that should work on any freshly installed Ubuntu system:

The Standard Way

/!\ This procedure gives you a full root shell! You can damage your system if you are not careful!

  • When booting up press `ESC` at the grub prompt.
  • Use the arrow keys to select the rescue mode option and press `enter`.

This will boot the system in rescue mode and you should arrive at a prompt to either enter the root password, or press `ctrl-d`. There is no root password by default in ubuntu, so just press `enter` and you will be logged in as root.

  • Now you can reset your password with: `passwd <username>`
  • You can than switch back to the normal GUI mode: `init 2`

Last resort

If the above does not work ( i.e. because there IS a password on the root account and you don't know it ) then you can try the following as a last resort.

/!\ This procedure gives you a full root shell! You can damage your system if you are not careful!

  • Turn your computer on.
  • Press `ESC` at the grub prompt.
  • Press `e` for edit.
  • Highlight the line that begins `kernel`, press `e` again.
  • Go to the very end of the line and add `rw init=/bin/bash`
  • press `Enter` and then then press `b` to boot your system.
  • To change your password, type: `passwd <username>`.
  • Type `reboot` to reboot your system.


Last resort 2

There is also another possibility to change your password using a bootable Linux CD. This is useful if you cannot boot from your bootloader (i.e. because you do not know the password or you broke something).

/!\ Be very careful again, this will give you full root access on the system and you might damage it.

(!) This is more advanced and will therefore need a little more preparations and understanding.

What you need:

  • The BIOS should try to boot from CD before it tries to do it from the harddrive. How to set this up is not in the scope of this article but you can have a look at your BIOS manual.
  • You need a some Live CD, the Breezy Badger install CD is enough for that.
  • You need to know what partition the Linux installation is on. You may find this out typing `fdisk -l` in the prompt of the Live CD.

In the following I assume that the partition is `/dev/hda1`, substitute it with whatever you found out.

What you need to do:

  • Boot from live CD and get a shell. On the install disk you need to go until the language selection. You have to press `alt-f2` and `enter` then.
  • Create an empty directory with `mkdir mnttmp` and mount the filesystem with `mount /dev/hda1 mnttmp`
  • Mount the proc-filesystem with `mount -o bind -t proc mnttmp/proc`. This is not really necessary, but might be better if you want to do more than just a password change.
  • Get a root shell on your Linux: `chroot mnttmp /bin/bash`
  • You now have a root shell. To change your password enter `passwd <username>`
  • In order to reboot your system, you have to clean up a little bit:
    • `exit`
    • `umount mnttmp/proc`
    • `umount mnttmp`
    • `reboot`
  • Boot the Linux you just modified, the user's password is changed to what you wanted it to be.

How to prevent all this

Since anyone who has physical access to your computer can do these things, it might be good to disable all of these tricks. I will not give you a full guided tour, but this list provide some hints:

  • Check the GRUB documentation for information on setting a GRUB password: `info grub`
  • Disable Boot from CD and the floppy drive in the BIOS
  • Set a BIOS password
  • Lock your computer case with a decent lock