How to Reset the Root Password in Linux

How to Reset the Root Password in Linux Техника

Reset Lost Linux Root Password from the Grub Menu

1. First and foremost, to recover a lost root password, we need to restart the Linux host, assuming you forgot the password for root.

2. Once the GRUB page appears, quickly select the “*Advanced options for GNU/Linux” option by pressing the down arrow key and Enter button.

grub-advanced-options

3. Now press e to edit the commands.

You need to modify it or change it from “read-only” mode to “read-write” mode. Find the line beginning with “Linux.” Look for ro and change it to rw. Add init=/bin/bash at the end of the line.

grub-edit-kernel-loading-menu

4. Press F10. This will display a screen with a prompt.

grub-boot-bash-screen

5. Mount your root file system in read-write mode:

grub-bash-screen-reset-password

Once you are done, type:

This will exit the prompt and reboot the computer.

Reset Lost Root Password Using Live CD

If you have a Linux Live CD/USB, then you can boot into it and use it to reset the root password.

1. Download the latest version of Ubuntu, and create a bootable Live CD/USB from it. Boot your system from the removable drive as opposed to your hard drive.

2. On the display screen select “Try Ubuntu.” This will bring you to the Live CD desktop.

ubuntu-live-cd-try-ubuntu

In most cases it will be “/dev/sda1,” although it can differ depending on how your hard disk is partitioned.

  mntrecover
  devsda1  mntrecover
ubuntu-livecd-mount-partition

6. At this point we need to jail ourselves in the “mnt/recovery” directory. This means that we are pretending to be on the regular Linux filesystem. This is simply known as chrooting.

Дополнительно:  Почему не работает кулер на ноутбуке и что делать в этом случае

8. Once completed, exit from the chroot shell:

9. Unmount the root partition:

and exit your root:

10. Lastly, remove the Live CD and reboot into your Linux system.

Frequently Asked Questions

1. How does full disk encryption affect my ability to change my root password?

Although encryption can complicate things when you’re trying to repair a problem on Linux, this is not the case when you’re trying to change the root password. You can still do it easily from grub as described above as long as you are able to gain access to the disk.

The only difference now is that outsiders won’t be able to just slide in and do the same themselves.

2. What is the difference between root and superuser password?

3. Can I create an expiration date for passwords?

Additionally, you could use the -w flag to set the number of days required for an advanced warning about the need to change the password . Typing passwd -w 7 root will send you warnings about changing the root password a week prior to the deadline you previously set with the -x flag.

Want to keep digging into Linux? We have a guide for setting up Bluetooth on Linux. You can also check out our list of tools to create your very own Linux distro!

Miguel Leiva-Gomez

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Content

  • Introductory
  • Recover a forgotten root password using the GRUB menu
  • Recover a forgotten root password using GParted Live
  • Conclusion

Introductory

It is not common to log in as root, so we do not use its password for a long time. We may forget and the sudo command is not available. If this happens, let’s look at two ways to recover your forgotten root password on Debian and Ubuntu.

To reset the forgotten root password, you must first log in to GRUB menu. To do this, you need to start / restart the computer. In this example today, I have two On a VirtualBox machine I will present the steps of this operation in parallel.

System restart / reboot

Boot the machine and wait for GRUB to start. For Ubuntu systems, if the GRUB menu does not appear automatically, press and hold the left button at the beginning of the boot process. key. So for me, the GRUB menus for Debian 10 (Buster) and Ubuntu 20.04 LTS (Focal Fossa) look like this:

Booting Virtual Machines - Debian 10 (Buster) and Ubuntu 20.04 LTS (Focal Fossa) - Booting GRUB Menus

In the beginning, until the windows fit side by side on the table, I will show the first few steps together.

Start the root console

On Debian, select «Advanced settings for Debian GNU / Linux» and on Ubuntu, select «Advanced options for Ubuntu». This is where the special options for both systems come in:

Дополнительно:  Как отключить блокировку экрана Windows 7: инструкция

GRUB menu - Advanced settings on Debian and Ubuntu

If you have more than one operating system, of course, select the appropriate system on which you want to reset the root password.

Then press the key, the GRUB parameters will appear:

Open GRUB parameters

Here, scroll down to the bottom of the text box where you will find the Linux kernel loader:

GRUB parameters - Find the Linux kernel load section

Here you have to change that ro (read only) rw (read / write), that is, to mount the root filesystem in writable mode, and to start the Bash-him.

rw maybe-ubiquity init=/bin/bash

Finally, it should look something like this:

GRUB parameters - Modify the Linux kernel load section

Of course, for other versions of GRUB / Debian / Ubuntu, there may be other options, but the point is to fix ro to rw and add the «init = / bin / bash» section to the end of the line.

To start the configuration, press key, you will get a root console:

Debian root console

In the case of Ubuntu, it loads a little more, and finally we get a root prompt here:

Ubuntu root console

Change root password

passwd root

Then enter any new password and repeat.

Changing the root password on Debian

Change root password on Ubuntu

exec /sbin/init

Login with root

Debian root login

Ubuntu root login

Recover a forgotten root password using GParted Live

If there is no GRUB loader installed on the machine, or the machine is booting with another boot manager program that we do not know, then as an alternative we have other options to reset our forgotten root password.

For this purpose, the Live installation kit of virtually any Linux distribution (which of course has one) is great, such as Debian or Ubuntu Live installers, the point is to boot a Linux system and have a root terminal or console.

In this example, I will perform this task with GParted Live. It is a Debian-based, featherweight small system designed specifically to perform such recovery, repair, and maintenance tasks. I have previously made another description of this, the steps of which I will not detail here, so you can find the link below on how to get it, how to write it to a flash drive, and how to start a root terminal in it (link opens in a new window meg):

Booting the root terminal

From now on, I will not split the examples for Debian and Ubuntu, because here the Live system will work on any distribution, we will have to reset the root password. So I’m now opening a root terminal in GParted Live, and the steps so far can be found in the description above:

GParted Live - Root terminal and GParted program

GParted Live starts the GParted partitioning program by default, which I leave outside so I have the drives, partitions, and markers in front of me. We will need these.

Mount a system partition

fdisk -l

GParted Live - Find a system partition

If you are not familiar with partitions, you can easily decide which partition you need based on the size, type, and boot-flag status of the partition.

Дополнительно:  Lucky Patcher v10.8.1

In this example, the virtual machine has multiple partitions, of which here is / Dev / sda1 The parameters just mentioned are 36 GB, type: Linux, ext4 file system, and boot flag. So in this example, this will be fine.

Create a mount point for this partition and mount it:

mkdir  /mnt/system
mount  /dev/sda1  /mnt/system

GParted Live - Mount a system partition

Chrooting the system partition

In the next step, we need to pretend that this mount point (/ mnt / system) is our regular filesystem, this is called chrooting:

chroot  /mnt/system

After issuing the command, it throws a warning that it can’t set the correct localization, but we don’t have to deal with that. We will then be taken to the root directory, which is already the root directory of the mounted drive:

GParted Live - Chrooting the system partition

Interestingly, the output of our prompt and our ls command also became colored here. This is because the original Debian 10 (Buster) minimal server installation anno I set the color prompt, and now the .bashrc file for this system has run from the / root directory. So from this we can see that the chroot succeeded. Thus, the output of the ls command also returned the contents of the mounted system partition.

Change root password

You can then easily change the root password:

passwd root

GParted Live - Change root password

Enter the new root password twice in succession.

Exit and reboot system

In the end, there was nothing left but to step back from everything:

Exit the chroot shell:

exit

Unmount the system partition:

umount /mnt/system

This is very important because if you do not unmount and restart the machine, the file system may be damaged!

And you can also exit root:

exit

GParted Live - Log out

Then remove the Live Installer from the DVD or USB and restart the computer.

Login with root

Login with root

Conclusion

With these two methods, we can rest assured that we can reset the root password if we accidentally forget it. However, this also means that if unauthorized people have access to our computer or laptop, they can change our root password and access our data in the same way. We can protect against this with disk encryption, which can make things harder for unauthorized intruders.

Forgot your Ubuntu login password? It happens.

If you haven’t used Ubuntu for some time, it’s only natural to not remember the password. The good news is that you don’t need to reinstall the entire operating system because of it. You can recover Ubuntu passwords easily.

The method mentioned here works for resetting an Ubuntu password in VMware, dual boot or single install. All you need is a little bit of patience and to run a couple of commands. You’ll reset the root password within minutes.

Forgot Linux Password on WSL? Here’s How to Reset it Easily

Forgot the password of your Linux distribution app you installed in Windows via WSL? No worries. You can easily reset the Linux password in WSL.

How to Reset the Root Password in Linux

How to Reset the Root Password in Linux

Reset Ubuntu password from recovery mode

Step 1: Boot into recovery mode

Switch the computer on. Go to the grub menu. Generally, it appears automatically – if not, then hold down the shift key or press Esc key until the boot menu appears.

If you’re using Oracle VirtualBox or VMware, you have to hold down the shift key when the logo of Oracle or VMware appears.

In the grub menu, select the “Advanced Options for Ubuntu”:

Advanced boot options in Grub menu of Ubuntu
This is grub screen

In here, you’ll see the option to go to recovery mode:

Boot into recovery mode

It will bring you to a black screen with several lines of output being displayed in a flash. Wait for a few seconds here.

Step 2: Drop to root shell prompt

Now you’ll be presented with different options for recovery mode. Here you need to choose “Root – Drop to root shell prompt“.  Just press the enter key to select this option. Like in the picture below:

Root shell prompt allows you to reset password in Ubuntu

You’ll see that when you select the root shell prompt option, an option to enter commands appears at the bottom. This is your root shell prompt and this is where you’ll use the commands to reset the password.

Step 3: Remount the root with write access

You need to have write access to the root partition. By default, it has read-only access.

Use the command below to remount it with write access:

mount -rw -o remount /

Step 4: Reset username or password

ls /home
passwd username

It prompts for a new password. Enter the new password twice.

Do note that nothing is displayed on the screen when you start typing the password. This is perfectly normal and actually a security feature in Linux systems. Just blindly type the password and press enter.

Enter new UNIX password:
Retype new UNIX password:

Voilà! There you go. You have just successfully reset the password. Now exit the root shell prompt:

exit

When you exit, you’ll be back at the recovery mode menu. Select the normal boot option here.

Use recovery mode to boot normal after resetting password in Ubuntu

There will be a warning about graphics mode compatibility. Don’t worry. A complete reboot will fix any issues with this.

You should now be able to log in with the new password.

Possible Troubleshoot:

While entering the new password you might be prompted with Authentication token manipulation error like this:

mount -rw -o remount /

Now try to reset the password again. It should work now.

As you can see, it is extremely easy to change Ubuntu password even if you’ve forgotten it. It will barely take a few minutes.

Alternate method to reset Ubuntu password

If for some reason you have difficulty dropping to the root shell and changing the password, you can try these steps.

Step 1

Reboot your computer. Hold shift to bring up the grub screen (if it doesn’t appear automatically). Press E at the grub prompt to edit the grub screen.

Step 2

Find the line starting with linux, change the ro to rw and append init=/bin/bash at the end of that line.

Editing grub to fix frozen boot issue with Ubuntu Linux
Change ro to rw and add init=/bin/bash at the end of this line

Step 3

Press ctrl-x to save your changes and boot.

In other words, your system will boot up to a passwordless root shell.

Step 4

Set your new password.

Once you’ve set the new password, exit the terminal. Just type reboot in the terminal or use the shutdown command.

shutdown -r now

Your password should be changed now.

If resetting Ubuntu passwords is this easy, isn’t this a security risk?

That’s a fair question. One of the main advantages of Linux over Windows is its security. But if “anyone” can reset the password, how come Ubuntu or other Linux distributions can be considered secure?

Let me explain a few things here. The main security risk is if someone hacks into your account from a remote location via the internet. That’s not happening here.

If anyone has physical access to your computer, the data in your computer is already at risk. Unless the entire disk is encrypted, anyone can “steal” your data using a live USB without even entering your installed operating system.

This lack of root password is a deliberate feature The “advanced options for Ubuntu” in the boot menu allow you to perform some specific root-related tasks from the “root shell prompt”. This is why you’re able to reset the Ubuntu password through this method.

Bonus Tip: Handling the possible keyring issue after changing the password

There is a keyring feature in Ubuntu that is used for keeping passwords locked and safe.

When you reset the forgotten password, the keyring remains unlocked and you may see an error message like this.

Enter Password To Unlock Your Login Keyring Ubuntu

Open the Passwords and Keys application and here, delete the Login passwords.

Delete Keyring Ubuntu
Delete Keyring Ubuntu

When you try to use Google Chrome again in Ubuntu, it will ask you to create a new keyring. Use the new login password as the keyring password.

Did it help you?

Donate Itsfoss

I hope I made things clear about resetting forgotten passwords in Ubuntu.

WSL (Windows Subsystem for Linux) is a handy tool for people who want to enjoy the power of Linux command line from the comfort of Windows.

Now, the problem is that if you haven’t used it for some time, you may forget the account password of WSL. And this will become a problem if you have to use a command with sudo because here you’ll need to enter the password.

reset wsl password

Don’t worry. You can easily reset it.

Reset forgotten password for Ubuntu or any other Linux distribution on WSL

To reset the Linux password in WSL, you have to:

  • Switch the default user to root
  • Reset the password for the normal user
  • Switch back the default user to the normal user

Let me show you the steps in detail and with screenshots. If you want a video, you can watch that as well.

Step 1: Switch to root as default user

username wsl
Note down the account username

This is done through Windows Command Prompt and you’ll need to know which command you need to run for your Linux distribution.

This information is usually provided in the description of the distribution app in the Windows Store. This is from where you had downloaded your distribution in the first place.

wsl distro command
Know the command to run for your distribution app

From the Windows menu, start the command prompt:

Start Command Prompt in windows
Start Command Prompt

In here, use your distribution’s command in this fashion. If you were using the Ubuntu app from Windows store, the command would be:

ubuntu config --default-user root

In the screenshot, I am using Ubuntu 20.04 app from the Windows store. So, I have used ubuntu2004 command.

wsl set root as default
Set root as default user in Linux app’s configuration

To save you the trouble, I am listing some distributions and their respective commands in this table:

Step 2: Reset the password for the account

passwd username

It will ask you to enter a new password. When you type here, nothing will be displayed on the screen. That’s normal. Just type the new password and hit enter. You’ll have to retype the new password to confirm and once again, nothing will be displayed on the screen while you type the password.

resetting wsl password
Reset the password for the regular user

Step 3: Set regular user as default again

ubuntu config --default-user username
set regular user as default wsl
Set regular user as default user

If you forgot the password again in the future, you know the steps to reset it.

If resetting WSL password is this easy, is this not a security risk?

Not really. You need physical access to the computer and access to the Windows account. If someone already has this much access, they can do much more than just change the Linux password in WSL.

Were you able to reset WSL password?

I gave you the commands and explained the steps. I hope this was helpful to you and you were able to reset the password of your Linux distribution in WSL.

If you are still facing issues or if you have a question on this topic, please feel free to ask in the comment section.

Оцените статью
Master Hi-technology
Добавить комментарий