In previous articles Recovering the Root Password (RHEL / CentOS 7) and Recovering the Root Password (Ubuntu) was how to Recover / Reset root Password from the Kernel.
In this guide, we will provide Information how to Recover / Reset root Password for any Server (Cloud, Dedicated) in Rescue mode.
Boot your Server into Rescue; if your Server is Cloud Server or Cloud VPS, we would recommend use Knoppix. If your Server is Dedicated, then just reboot Server with the available Rescue option you have.
1- Recover root Password (Cloud Server, Dynamic Cloud Server)
After booting your Server into Rescue using Knoppix, you need to access your Server with the provided Emulator (KVM, VNC)
First, switch to root user, “this is not your Server root, it’s Knoppix root user”:
# sudo su -
Then, either to activate the SSH Service in order to use your SSH Client (MobaXterm, Putty), or you can proceed with the steps from (KVM, VNC).
If you would like to use your SSH Client, then you need to set password for Knoppix root user, after that you can access your Server using your SSH Client:
# passwd root
Please refer to How to mount Cloud / VPS Cloud in Rescue to Activate your Logical Volume and mount to /mnt Directory.
After mounting your Logical Volume to /mnt Directory, you need to mount the following system files:
# mount --bind /dev /mnt/dev
# mount --bind /dev/pts /mnt/dev/pts
# mount --bind /proc /mnt/proc
# mount --bind /sys /mnt/sys
Then, chroot /mnt, once you chroot /mnt, you are can then proceed as if you were working with your usual server configuration.
# chroot /mnt
Then proceed with changing your root Password:
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Then exit chroot, and unmount file systems, then reboot Server:
# exit
# umount -a
# reboot
Eject Knoppix DVD, and now you can access your Server using your new Password.
2- Recover root Password on other Servers
– Dedicated Servers
After booting your Server into Rescue, access your Server either via Serial Console, or normal SSH, then you need to check your Server Disks and Partitions with fdisk command:
# fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x76a7d556
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8390655 4194304 fd Linux raid autodetect
/dev/sdb2 8390656 12584959 2097152 82 Linux swap / Solaris
/dev/sdb3 12584960 1953525167 970470104 fd Linux raid autodetect
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x76a7d556
Device Boot Start End Blocks Id System
/dev/sda1 2048 8390655 4194304 fd Linux raid autodetect
/dev/sda2 8390656 12584959 2097152 82 Linux swap / Solaris
/dev/sda3 12584960 1953525167 970470104 fd Linux raid autodetect
Disk /dev/md3: 993.8 GB, 993761296384 bytes, 1940940032 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md1: 4294 MB, 4294901760 bytes, 8388480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vg00-usr: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vg00-var: 112.7 GB, 112742891520 bytes, 220200960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vg00-home: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
With having /dev/md1 and /dev/md3 then, you need check your RAID in order to determine which drive has sda1:
# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[1] sda1[0]
4194240 blocks [2/2] [UU]
md3 : active raid1 sdb3[1] sda3[0]
970470016 blocks [2/2] [UU]
So, we mount /dev/md1, because it contains the file system we need:
# mount /dev/md1 /mnt
# mount /dev/mapper/vg00-var /mnt/var
# mount /dev/mapper/vg00-usr /mnt/usr
# mount /dev/mapper/vg00-home /mnt/home
# mount --bind /dev /mnt/dev
# mount --bind /dev/pts /mnt/dev/pts
# mount --bind /proc /mnt/proc
# mount --bind /sys /mnt/sys
Then, chroot /mnt, once you chroot /mnt, you are can then proceed as if you were working with your usual server configuration.
# chroot /mnt
Then proceed with changing your root Password:
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Then exit chroot, and unmount file systems, then reboot Server:
# exit
# umount -a
# reboot
Boot your Server back to Local, and now you can access your Server using your new Password.
Your mode of explaining the whole thing in this article
is actually nice, every one be able to effortlessly know it, Thanks a lot.
Thanks in favor of sharing such a fastidious opinion, paragraph is pleasant, thats why i have read it entirely
Fantastic goods from you, man. I’ve understand your stuff previous to and you are just too wonderful. I actually like what you’ve acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can’t wait to read far more from you. This is really a terrific site.