个人工具

“UbuntuHelp:LostPassword”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{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...)
 
 
(未显示2个用户的5个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/LostPassword}}
 
{{From|https://help.ubuntu.com/community/LostPassword}}
 
{{Languages|UbuntuHelp:LostPassword}}
 
{{Languages|UbuntuHelp:LostPassword}}
 
 
=== Lost Password? ===
 
=== 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.  
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, because this step will give you '''full root access''' to your system and you can really damage your system!
 
+
/!\ 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!
 
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:
 
Now let us start with a way that should work on any freshly installed Ubuntu system:
 
 
=== The Standard Way ===
 
=== The Standard Way ===
 
 
/!\ This procedure gives you a '''full root shell'''! You can damage your system if you are not careful!
 
/!\ This procedure gives you a '''full root shell'''! You can damage your system if you are not careful!
 +
<ol><li>When booting up press '''ESC''' at the grub prompt and use the arrow keys to select the rescue mode option and press '''enter'''. (Some newer installations may hide the grub menu at boot, if this is the case, hold shift to get to the grub menu)
 +
</li><li>This will boot the system in rescue mode and you should arrive at a prompt that looks like this</li></ol>
  
* When booting up press `ESC` at the grub prompt.
+
<pre><nowiki>
* Use the arrow keys to select the rescue mode option and press `enter`.
+
root@something
 
+
</nowiki></pre>
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. 
+
<ol><li>To reset your password type this in</li></ol>
 
+
* 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:
+
<pre><nowiki>
 +
passwd <username>
 +
    </nowiki></pre>
 +
and then enter you new password.
 +
<ol><li>Once you are done resetting your password you  can than switch back to the normal GUI mode by putting this in</li></ol>
  
* 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.
+
<pre><nowiki>
* Create an empty directory with `mkdir mnttmp` and mount the filesystem with `mount /dev/hda1 mnttmp`
+
init 2
* 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.
+
  </nowiki></pre>
* Get a root shell on your Linux: `chroot mnttmp /bin/bash`
+
If if appears to boot normally, but you see a message that says:
* You now have a root shell. To change your password enter `passwd <username>`
+
Give root password for maintenance
* In order to reboot your system, you have to clean up a little bit:
+
(or type Control-D to continue):
** `exit`
+
then you will have to try a different trick below.  
** `umount mnttmp/proc`
+
=== The Other Way ===
** `umount mnttmp`
+
If the "Standard Way" does not work for you and you recieve the "Give root password for maintenance" message,
** `reboot`
+
you can recover your password using the following steps
 +
1. Reboot your computer
 +
2. Press '''ESC''' at the grub prompt.
 +
3. Select your image.
 +
4. Highlight the line that begins kernel and press 'e' to edit
 +
5. Go to the very end of the line, change the ro to rw and add init=/bin/bash
  
* Boot the Linux you just modified, the user's password is changed to what you wanted it to be.
+
press enter, then press b to boot your system.
 +
Your system will boot up to a passwordless root shell.
 +
6. Type in '''passwd username'''
 +
7. Set your password.
 +
8. Type in '''reboot'''
  
=== 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
 
 
----
 
----
[[category:CategorySecurity]] [[category:CategoryCleanup]]
+
[[category:CategorySecurity]]  
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 23:11的最新版本

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. /!\ Be careful, because this step will 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!

  1. When booting up press ESC at the grub prompt and use the arrow keys to select the rescue mode option and press enter. (Some newer installations may hide the grub menu at boot, if this is the case, hold shift to get to the grub menu)
  2. This will boot the system in rescue mode and you should arrive at a prompt that looks like this
root@something
  1. To reset your password type this in
passwd <username>
    

and then enter you new password.

  1. Once you are done resetting your password you can than switch back to the normal GUI mode by putting this in
init 2
  

If if appears to boot normally, but you see a message that says: Give root password for maintenance (or type Control-D to continue): then you will have to try a different trick below.

The Other Way

If the "Standard Way" does not work for you and you recieve the "Give root password for maintenance" message, you can recover your password using the following steps 1. Reboot your computer 2. Press ESC at the grub prompt. 3. Select your image. 4. Highlight the line that begins kernel and press 'e' to edit 5. Go to the very end of the line, change the ro to rw and add init=/bin/bash

press enter, then press b to boot your system. Your system will boot up to a passwordless root shell. 6. Type in passwd username 7. Set your password. 8. Type in reboot