Let's look at several ways to reset the system password in Linux. You probably know that the root user has the right to change the password of any user in the system. What if you forgot your root password? That's about it and will be discussed in the article.
When recovering a password (root or any other user), there are two different situations that require a different approach.
When to use GRUB
If you have the GRUB boot loader installed and you have access to edit the boot parameters of the selected line, the task becomes very simple. Follow the further recommendations and get root rights as soon as possible. And as soon as you become a root, you can immediately do anything.
In the GRUB bootloader window, select the line with the required Linux version for which you need to reset the password.
Click 'e' to edit. Select a kernel string. Add 'single' to the end of the line. Click 'b' to download. If the system continues to ask for the root password, add init = / bin / bash to the end of the line. Press 'b' again to load
')
After that, you will either see an invitation for the root, or a restoring menu where you need to select the line with the root. Use passwd <username> to change the password of any user.
Run the reboot command to reboot the system and then log in with a new password.
It should also be noted that some distributions create a recovery mode during installation. If there is such an item in your GRUB menu, you do not need to perform all of the above steps, just select the recovery mode and then the invitation for root in the subsequent dialog box.
When it’s not possible to use GRUB
If you don’t use GRUB for some reason, you can reset your password using the live CD (I’ll use the Ubuntu live CD, you can take any other). Just follow the further instructions:
Boot from the live CD
Select “Try Ubuntu without changes on your computer” (Try Ubuntu without your changes).
When the system is ready, launch a terminal window and get ready to perform some actions on the command line.
Type in the terminal window sudo fdisk -l . As a result, we will find out in which disk partition Linux is installed and the name of the hard disk itself, in the example presented, the partition we need is called / dev / sda1 . If you know the exact section, you can skip this step.
Next, we need to mount the Linux partition. To do this, create a folder as a mount point using the command: sudo mkdir / media / linx_part
Mount the linux partition with sudo mount / dev / sda1 / media / linx_part
Change root in mounted partition - sudo chroot / media / sda1
Use passwd to change the current password to a new one.
Reboot the system using the reboot command
Perhaps you have your own password recovery methods? Share them.