How to change/reset the root password on Ubuntu Linux
Anyone can lose or forget the password of a system administrator of a computer running GNU / Linux, but in these circumstances you should not panic, because a way to recover access to your workstation exists and is also very easy to perform.
In the following passages of this guide, in this regard, we will explain to you how to change or reset the root password on Linux Ubuntu (any version) if it has been lost or modified by a third party, a very difficult event, but not impossible. So let’s see how to proceed.
Before formatting the hard drive and reinstalling the operating system, you need to know that there are several ways to recover the password through ” grub “, the default Bootloader for most Linux distributions, including Ubuntu.
First of all, the first thing to do is to turn on the computer, so when loading the Bootloader, you will have to press the Esc key to access the boot and kernel options. You will notice, at this point, the presence of the list of installed operating systems and various kernel versions.
Having regained access to your desktop, you can proceed with eliminating obsolete ones by typing the command: sudo apt-get autoremove; or from Synaptic, by searching for the keywords ” linux-image ” and ” linux-headers ” and ticking them for removal.
Meanwhile, you will need to use the arrow keys to go to highlight text strings. So select the kernel you usually use and press the E key.
At this point, you will see a window similar to the one shown in the figure. Then place the cursor at the end of the line and press the E key again (stands for ” Edit ” ). After pressing it, you simply need to write the following code: rw init=/bin/bash. Now press the B key (stands for ” Boot ” or reboot).
If the procedure has been performed correctly, a terminal window will appear in which you can execute all the commands with system administrator privileges. From here you will have the possibility to change the password of any user of the Linux system, including the root user, by typing from shell: passwd username new_password.
Now press Enter. Remember that the username is the name of the user whose password you want to change. In the case of the root user, it will be necessary to insert the word of the same name: passwd root new_password, then press enter. At this point, the string ” new_password ” will have to be replaced with the actual one, if your password is ” foo “, the command will be: passwd root foo. Once again you will have to click on Enter.
What you will need to do now is proceed with rebooting the system using the command: reboot, then continue by pressing the Enter key. An important recommendation is to write down your login credentials in some file or in a sheet, so as not to have to repeat the whole operation again in the future!
Finally, remember that in GNU / Linux systems passwords are encrypted and, once they are lost, there is no way to recover them except by following particular procedures, a bit long, like the one we have illustrated.
Note :
- Equip yourself with post it and a pen before starting to make changes.
- Do not modify any other commands in step 3 absolutely, stick to what is written unless you know where you are getting your hands.
- The same guide also applies to other Linux distributions that have grub as a bootloader.