How to Change or Reset Root Password in Linux

If you have not logged in as a root user for a long time and have not saved the login information anywhere, there is a chance that you may lose access to the credentials for your system. It is not an unusual occurrence, but rather, a common issue, which most Linux users have probably encountered before. If this happens, you can easily change or reset the password via the command-line or the GUI (Graphical User Interface).

But what do you do if the root password must be modified or reset?

This article shows you how to change the root password for your Linux Mint 20 system via three different methods.

Note: To change the root password, you must have either the current root password, sudo privileges, or have physical access to the system. It is also recommended to save the new password(s) in a secure location to be accessed when needed.

In this article, we will cover how to:

  1. Change or reset root password as root user
  2. Change or reset root password as sudo user
  3. Change or reset root password using GRUB menu

It is worth mentioning that all the commands included in this article have been tested in the Linux Mint 20 system. These commands have been performed in the Terminal, which can be opened using the Ctrl+Alt+T key shortcut, or by clicking on the terminal icon present in the taskbar of the Linux system.

Change or Reset Root Password as Root User

If you have the current root password and want to reset it, you can do so by using the ‘passwd’ command. Perform the following steps to change or reset the root user password:

First, log in as a root user using the following command in Terminal:

$ su root

When you are asked to provide the password, enter the current root password. Next, you will see the Terminal prompt changed to ‘#,’ indicating that you are now logged in as the root user.

To change the root password, type the following command in the Terminal:

$ passwd

You will be prompted to enter a new root password. Type the new password and hit the Enter key. Then, re-enter the password and press the Enter key to avoid any typos.

After entering the password, you will be shown a message saying that the password has been updated successfully.

Change or Reset Root Password as Sudo User

The root password can also be changed by a standard user with sudo privileges. You can change or reset the root user password by following the steps given below:

Type the following command as a sudo user in the Terminal to change the root password.

$ sudo passwd root

You will be asked to type a new password for the root user. Enter a new password and press Enter. Then, re-enter the password and press the Enter key to avoid any typos.

After entering the password, you will be shown a message saying that the password has been updated successfully.

Change or Reset Root Password Using GRUB Menu

If you are a root user and have forgotten the root password to your system, then you can reset the root password using the GRUB menu. GRUB is the first program that starts at system boot. However, keep in mind that physical access to your system is required to use the method described in this section.

To reset or change the root password using the GRUB menu, perform the following steps:

Restart the system and hold the Shift key or press the Esc key to enter into safe mode (recovery mode). Once you have entered safe mode, you will see the GRUB menu, as shown in the following screenshot.

Next, navigate to the Advanced options.

Then, to switch to the edit window, click ‘e’ on the keyboard.

You will see the following screen:

Scroll down the screen until you see the following line:

“linux /boot/vmlinuz-5.4.0-26-generic root=UUID=35\2d26aa-051e
-4dbe-adb2-7fbb843f6581 ro quiet splash”

Replace ‘ro‘ with ‘rw’ in the above line and, at the end of the line, append ‘init=/bin/bash’. It should now look like this:

“linux /boot/vmlinuz-5.4.0-26-generic root=UUID=35\
2d26aa-051e-4dbe-adb2-7fbb843f6581 rw quiet splash init=/bin/bash

Adding ‘rw’ and ‘init=/bin/bash’ in the above line basically tells the system to log in to bash with read/write privileges. Note that this configuration will only apply for the current boot, not for subsequent boots.

Now, use the F10 key or the Ctrl+X shortcut to boot up to a command prompt, as shown in the following screenshot.

In the command prompt that appears, type the following command:

$ passwd root

You will be prompted for the root password. Input the root password and press the Enter key. Then, retype the password and press Enter to avoid any typos.

Note: You can change not only the root password but also any user’s password using this process.

After entering the password, you will then see a message stating that the new password has been updated.

Finally, use the Ctrl+Alt+Delete shortcut or type the following command at the command prompt to exit and reboot your system.

exec /sbin/init

That is all you need to do to change or reset the root password of your Linux Mint 20 system without the sudo or root login. It is good practice to change the password frequently after some time, especially if you think it has been compromised.

Conclusion

In this article, we have identified three different methods to modify or reset the root password on your system. You can opt for any method, based on the privileges you have. If you have the root password or sudo privileges, you can easily reset the root password using the simple ‘passwd’ command. Otherwise, you can use the GRUB menu to change the root password, but only if you have physical access to the system.

I hope this article has helped you in changing or resetting the root password of your system.



from Linux Hint https://ift.tt/3ok53vG

Post a Comment

0 Comments