Posts tagged ‘root password’

Recover the root password on Linux

There are many different ways to recover a lost root password on Linux systems. These are two of them:

When the Grub screen appears, press ‘e’ and append ’1′ to the line. The system will boot in single user mode. When you are presented the root prompt type the password command to change the password.

Another option is to mount the root filesystem and do a chroot:

# mkdir /mnt/system
# mount /dev/sda1 /mnt/system
# chroot /mnt/system
# passwd

In the first case you can prevent password recovery assigning a password to Grub.

# /sbin/grub-md5-crypt

This command returns a MD5 hash of the entered password.

Next, edit the Grub configuration file /boot/grub/grub.conf and add the following line (replace ‘password-hash’ with the grub-md5-crypt command output):

password --md5 password-hash

Now Grub doesn’t allow direct access to the edit or command menus. You have to press ‘p’ and enter the password.