How to Reset Root Password on
Debian or Ubuntu
If you forgot the root password for your Debian system, do not panic. There is an easy way to reset the password. Linux provides a special mode called "recovery mode" or "single user mode,"
The recovery mode is used when you need to perform file system maintenance and recovery, or conduct security vulnerability auditing in an isolated environment. You can also reset the root password in the recovery mode.
This is the Same mode as one would find on a Windows OS when you're booting into SafeMode for administrative maintenance purposes.
To BOOT into the recovery mode on Debian or Ubuntu,
1. Hold down SHIFT key after powering on your Linux machine. You will then be presented with GRUB menu.
2. Select "recovery menu" option by pressing down arrow key. DO NOT press ENTER at this point, but press "e" key to enter edit mode.
You will see "GRUB" edit screen where you can edit GRUB boot parameters.
Move your cursor to the line starting with "linux /boot/vmlinuz-......", and go to the end of that line. Append "init /bin/bash" right there, as shown below.
Then press Ctrl+X to proceed. After all subsequent booting sequence is over, you will finally get a root prompt.
In the recovery mode, the root partition is mounted as read-only by default, hence you will not be able to make any changes to root password.
To be able to reset the root password, you need to re-mount the root partition as read & write.
First, find out what the root partition of your system is, by using "fdisk -l" command.
As shown in the screenshot above, partition marked with "*" under "Boot" column is the root partition of your system (e.g., /dev/sda1).
Remount the root partition as read-write, and finally reset the password, using passwd command..
$ mount -o remount,rw /dev/sda1 /
$ passwd
$ passwd
To Sum up, Here's what you need to DO:
1. Boot Into Recovery Mode:
Hold down the SHIFT key right after powering up the server until you get the GRUB MENU
2. Enter Recovery Menu:
Press the DOWN ARROW KEY until you get to "RECOVERY MENU" and press letter " E "
3. Get to the Line where you need to make the changes:
Press DOWN KEY until you get to the line that starts with: "linux /boot/vmlinuz-......." go to the end of the line and APPEND "init /bin/bash"...Then PRESS CTRL+X and after reboot you would land in the root prompt.
4. Check which partition is the Root partition:
Type "fdisk -l" and hit Enter, The partition marked with "*" is the Root partition, the name is described under SERVICE BOOT. Ex: /dev/sda1
5. Mount the Root partition as Read & Write:
$ mount -o remount,rw /dev/sda1/
6. Change the Password:
$passwd YOURNEWPASSWORD (change YOURNEWPASSWORD with your own password)
That's all to it, now reboot and you should have your new password active.
No comments:
Post a Comment