Friday, September 14, 2018

How to Reset the Root Password in Linux

https://www.maketecheasier.com/reset-root-password-linux


In Linux, regular users and superusers are allowed to access services via password authentication. In the case a regular user can’t remember his/her password, a superuser can reset the password of a regular user right from the terminal. However, what if the superuser (or root user) loses his/her password?
To recover the lost password of a superuser (or root user),  it is done quite differently. Nonetheless, this method of recovering a lost password allows any malicious user with physical access to your Linux host to gain complete ownership.
In this article we will  look at how to recover a lost root password in Linux two different ways.
Note: the method of resetting a root password is similar for most distros. In this article we are using Ubuntu. Also, we will be using “root password” throughout the tutorial, but it can refer to a superuser’s password, too.</>
1. First and foremost, to recover a lost root password, we need to restart the Linux host, assuming you can’t remember the password for root (or superuser).
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.” After, look for “ro,” and change it “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 filesystem in read-write mode:
6. You can now reset your lost root password by using the following command:
Alternatively, you can change the password of the super user with the command:
grub-bash-screen-reset-password
Once you are done, type:
to exit the prompt and reboot the computer.
If you have a Linux Live CD (or USB), then you can boot into it and use it to reset the root password, too. In our example we will use a Ubuntu Live CD.
1. Download the latest version of Ubuntu, and create a bootable Live CD/USB from it. Boot your system from it.
2. On the display screen select “Try Ubuntu.” This will bring you to the Live CD desktop.
ubuntu-live-cd-try-ubuntu
3. Open the terminal, and type the following command to become root:
4. Next, we need to find out the location of the hard disk partition. Use the following command:
In most cases it will be “/dev/sda1,” though it can differ depending on how your hard disk is partitioned.
5. Mount the hard disk partition of the system to be recovered using the following command:
ubuntu-livecd-mount-partition
6. At this point we need to jail ourselves in the “mnt/recovery” directory. What this means is that we are pretending to be on the regular Linux filesystem. This is simply known as chrooting.
7. Use the following command to reset your root password:
or us:
to reset the password of a superuser.
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.
Changing the root password in Linux is easy, though it requires you to venture into the dark realm of the command line. Do note that anyone who has access to your computer can use this method to reset your superuser or root password. One precaution you can take is to encrypt the whole hard disk so it can’t be booted or mounted so easily.

No comments:

Post a Comment