How to Reset the Root Password in Linux
As a Linux user, there may come a time when you forget or need to reset the root password. Luckily, resetting the root password is relatively easy and straightforward. In this article, we’ll walk through the steps needed to reset the root password in Linux.
Step 1: Boot into Single User Mode
The first step in resetting the root password is to boot your Linux system into single-user mode. This can be done by rebooting your system and interrupting the boot process before it finishes. Once you’ve interrupted the boot process, you should be presented with the GRUB menu. From there, select the default or most recent kernel and press “e” to edit the boot configuration.
Next, find the line that starts with “linux” and add “single” at the end of the line, as shown below:
linux /boot/vmlinuz-4.15.0-32-generic root=UUID=1234-5678 ro single
Once you’ve made this change, press F10 or Ctrl+X to boot into single-user mode.
Step 2: Mount the Filesystem
In single-user mode, you need to mount the filesystem as read-write so you can reset the root password. You can do this by running the following command:
mount -o remount,rw /
Step 3: Change the Root Password
Now that the filesystem is mounted as read-write, you can change the root password using the “passwd” command. Simply type in “passwd root” and then follow the prompts to set a new root password.
Step 4: Reboot Your System
Once you’ve reset the root password, it’s time to reboot your system. You can do this by running the “reboot” command, which will restart your system and take you to the login screen.
That’s it! You’ve successfully reset the root password in Linux. It’s important to note that resetting the root password can be a security risk, so be sure to keep your new password secure and private. Additionally, if you’re running a Linux distribution with SELinux enabled, you may need to restore the previous SELinux contexts for your files and directories using the “restorecon” command.