Web Analytics Made Easy - Statcounter
Tech

How to Reset the Root Password in Linux

Forgetting the root password in Linux can be stressful, but resetting it is straightforward if you have physical or administrative access to the system. Below is a step-by-step guide to resetting the root password on most Linux distributions.

Steps to Reset the Root Password

1. Reboot the System

First, restart your Linux machine. If it’s already running, use:

sudo reboot


or

ADVERTISEMENT
systemctl reboot

2. Interrupt the Boot Process

When the system starts, quickly press Esc, Shift, or e (depending on your bootloader) to access the GRUB menu.

3. Edit the Boot Entry

  • Highlight the Linux kernel entry.
  • Press e to edit the boot parameters.
  • Find the line starting with linux or linux16/linuxefi.
  • Append rd.break (for systems using initramfs) or replace ro with rw init=/bin/bash to drop into a shell.

4. Remount the Filesystem with Write Permissions

If using rd.break, run:

mount -o remount,rw /sysroot
chroot /sysroot


If using init=/bin/bash, the filesystem should already be writable.

5. Reset the Root Password

Now, reset the password using:

passwd root


Enter a new password twice when prompted.

6. Update SELinux (If Enabled)

For systems with SELinux, run:

touch /.autorelabel


This ensures proper relabeling on the next boot.

7. Reboot the System

Exit the shell and reboot:

exit
reboot -f

Conclusion

Resetting the root password in Linux is a simple process if you follow these steps carefully. Always ensure you have proper authorization before performing such actions on a system.

By following this guide, you can regain access to your Linux machine in minutes!

Pro Tip: To avoid forgetting passwords, consider using a password manager or securely storing credentials.

ADVERTISEMENT

Related Articles

Back to top button

You Want Latest Updates?

X