how to recover forgotten root password in Linux

how to recover forgotten root password in linux

Recovering a forgotten root password in Linux can be a bit tricky but it is possible. Here’s a general guide on how to do it, but keep in mind that the process may vary depending on your Linux distribution.

Boot into Single User Mode:

  • Reboot your Linux system.
  • When the GRUB or boot loader menu appears, select the Linux distribution you want to boot into.
  • Press the “e” key to edit the boot parameters.
  • Find the line starting with “linux” or “linux16” or “linuxefi” (depending on your system) and look for the section that includes “ro” or “ro quiet.” Replace “ro” with “rw” and append “init=/bin/bash” at the end of the line.
  • Press “Ctrl + X” or “F10” to boot with the modified parameters.

Remount Root Partition:

The system will boot into single-user mode with a root shell. The root partition will be mounted as read-only, so you need to remount it as read/write with the following command:

Bash
mount -o remount,rw /

Reset the Root Password:

Now that the root partition is mounted in read/write mode, you can reset the root password by using the passwd command:

Bash
passwd

You will be prompted to enter the new root password twice.

Update SELinux Context (if applicable):

If you are using SELinux, you may need to update the security context on the password file. Use the following command to do so:

Bash
touch /.autorelabel

Reboot:

After resetting the root password and updating the SELinux context (if necessary), you can reboot your system:

Bash
reboot

After the reboot, you should be able to log in as root using the newly set password. Keep the new password secure and remember it to avoid having to go through this process again.

Use a live CD or USB

  1. Boot your system from a live CD or USB.
  2. Once you are booted into the live environment, open a terminal window.
  3. Type the following command to mount the root partition of your hard drive:
Bash
mount /dev/sda1 /mnt
  1. Change to the /mnt directory:
Bash
cd /mnt
  1. Change the root password using the passwd command:
Bash
passwd root
  1. Once you have changed the root password, reboot your system.

It’s important to note that these steps are intended for use on your own system or a system that you have explicit permission to modify. Attempting to reset the root password on someone else’s system without their consent is illegal and unethical.

Total
0
Shares

Leave a Reply

Previous Post
What are the tasks of the system administrator

What are the tasks of the system administrator

Next Post
how linux boots, about init process working... what run levels in linux

how linux boots, about init process working… what are run levels in linux

Related Posts