A Root Password can be exceptionally difficult to recover, if you loose or forget it. I think I would go as far as to say, the Root Password is nearly impossible to recover. However, if you are using Debian GNU/Linux, it may be possible to re-set the Root Password, to a new password, to be used going forward.
The process here is possible only if:
- You are using the GNU GRUB boot loader &
- Your root partition is not encrypted!
This process wont be as difficult as it may seem. If you will simply follow the steps I give you very carefully, I’m sure you will be pleasantly surprised. It is important that you read this entire page of directions completely, before actually performing any of the steps. This way if you have any questions or concerns, you can address them before starting the process.
Root Password Changing Process
- To get started, your will either need to reboot your system, or turn it on from the “Powered Off” state.
- When Grub loads, select the kernel that you want to edit using the up/down arrows. (If you’ve only installed one Linux Operating System, the kernel that is selected and is at the top is the default kernel you use. Also, unless you have configured your system not to automatically load the default kernel, you have to be quick in doing this, or it will proceed to boot into the default kernel in just a few seconds.)
- You will then press the “e” key on your keyboard to edit the selected kernel.
- Using your up/down arrows, scroll to the line with the kernel on it and press the “e” key again.
- At the end of the line, add…
…then hit the <enter> key. This tells the system that after loading the kernel, go directly to a bash shell, and then takes you back to the kernal screen.
- Then press the “b” key to boot. The system will load and take you to the command/bash prompt (i.e. sh-3.1#).
- At this point, your root partition is mounted as a “read only” partition, so you won’t be able to change the password on it until you mount it as a “readable/writeable” partition. So, at the command/bash prompt (i.e. sh-3.1#) type…
sh-3.1# mount -orw,remount /
…then hit the <enter> key. This tells the system to remount the partition with the new option “rw” (readable/writeable).
- Now, you will change the password. At the command/bash prompt (i.e. sh-3.1#) type…
…then hit the <enter> key. You will be prompted to enter a new unix password and then confirm it. Each time you type your new password in you will need to hit the <enter> key.
- After selecting & confirming your new password you will get a message:
passwd: password updated successfully
This confirms that your new password was entered and confirmed and has now been saved. You will notice that you have also been returned to the command/bash prompt (i.e. sh-3.1#).
- You will now need to remount the file system as read-only. At the command/bash prompt (i.e. sh-3.1#) type…
sh-3.1# mount -oro,remount /
…then hit the <enter> key. This tells the system to remount the partition with the default option (read only).
- The process will complete and you will be returned to the command/bash prompt (i.e. sh-3.1#), with you partitions intact as they were before we performed the password change. At the command/bash prompt (i.e. sh-3.1#) type…
sh-3.1# exec init
…then hit the <enter> key. This tells the system to replace the current process with “init” and start the system. (Which is what the kernel would have done by default before we edited it with init=/bin/sh to take us to the command/bash prompt.) Your system will now boot normally.
Root Password: Summary
These steps, for changing the Root Password, have been tested on a Debian GNU/Linux system running the “SARGE” release, and work just fine. However, I have not tested these steps in “ETCH”, “LENNY” or “SQUEEZE” releases.