Reset Linux root password. Guide to reset Linux root password.

Reset Linux root password

Resetting Linux root password. Guide to reset Linux root password.

First off you need some sort of “physical access to this box” to be able to reset linux root password if its not your desktop then some sort of remote kvm access (kvm keyboard video and mouse)

Note these instructions are based on CentOS so should work for any Red Hat based distro although may differ.

At the grub prompt press e to enter edit mode.

Select the second line press e again.

At the end of a similar entry, Your Grub entry will probablly not look the same as this.

kernel /vmlinuz-2.6.18-308.4.1.el5 ro root=/dev/sda3

Add init=/bin/sh (The steps so far should work on Debian/Ubuntu although with Debian/Ubuntu you might need to use /bin/bash instead of /bin/sh, due to Debian/Ubuntu symlinking /bin/sh to /bin/dash rather than /bin/bash)

kernel /vmlinuz-2.6.18-308.4.1.el5 ro root=/dev/sda3 init=/bin/sh

Now press the enter key and then b to boot.

This will take you into single user mode.

Now mount the root partition in read and write mode so that the changes can be committed.

mount -o remount,rw /

Once the file system is mounted type the following.

passwd root

You will prompted for the new password and then to confirm.

You have now reset Linux root password so reboot.

Alternatively this can be done with a livecd.

1. Boot the livecd.

2. Mount the partition (replace * with the drive letter).

mount /dev/sd* /mnt/point

3. Use chroot to reset the root password on the disk (rather than the livecd)

chroot /mnt/point passwd root

You will now be prompted to change password, but as this is chrooted it only affects the partition you mounted and not the host. So you could do this from a desktop or server also over nfs and maybe samba.

chroot

chroot creates a isolated environment. So if you chroot /mnt/mountpoint it locks /mount/mountpoint into a chroot jail (so the same as a htdocs basically. Restricts the user to a directory that is “there root” they cant go above).

So chroot /mnt/point yum check-update (If yum is installed within /mnt/mountpoint)

Would check for updates to the mounted chroot jail .

So if you ran  chroot /mnt/point yum check-update && yum update, the system you mounted it on will not be updated. But the system that’s within the chroot jail will.

Linux, Virtual & Dedicated Servers , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

13 + eighteen =