Open In App

Reset a lost Linux administrative password and Explanation

Last Updated : 20 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The recovery mode does not work always because many systems will ask for the root password for logging in. Now, since you do not know the root password in the first place, that trick will fail. In such a case, you can try these which is the easiest ways to get reset the linux password.

1. Use ‘sudo su’ or ‘sudo -i’
sudo passwd root or passes sudo su or sudo -i to first get the root power and then run the passwd command, he or she would be able to reset the root password. It does not work everywhere think of a situation where you do not have a root password then.

2. Grub Method

  • Turn your computer on.
  • Press ESC at the GRUB prompt.
  • 1

    linux   /boot/vmlinuz-3.7.10-1.1-desktop root=UUID=ba08039b-33ba-4074-857c-9688856c3583   video=1366x768 resume=/dev/disk/by-id/ata-WDC_WD3200BEVT-75ZCT2_WD-WXE1A9033884-part2 splash=silent quiet showopts
    

    OR

     kernel  /boot/vmlinuz-3.7.10-1.1-desktop root=UUID=ba08039b-33ba-4074-857c-9688856c3583   video=1366x768 resume=/dev/disk/by-id/ata-WDC_WD3200BEVT-75ZCT2_WD-WXE1A9033884-part2 splash=silent quiet showopts

    2

    Press e for edit

  • Go to the very end of the line and add init=/bin/bash . So the line will start looking like this:
    linux   /boot/vmlinuz-3.7.10-1.1-desktop root=UUID=ba08039b-33ba-4074-857c-9688856c3583   video=1366x768 resume=/dev/disk/by-id/ata-WDC_WD3200BEVT-75ZCT2_WD-WXE1A9033884-part2 splash=silent quiet showopts init=/bin/bash
    

    OR

    kernel  /boot/vmlinuz-3.7.10-1.1-desktop root=UUID=ba08039b-33ba-4074-857c-9688856c3583   video=1366x768 resume=/dev/disk/by-id/ata-WDC_WD3200BEVT-75ZCT2_WD-WXE1A9033884-part2 splash=silent quiet showopts init=/bin/bash
    
  • Press Enter, then Press b to boot your system. Your system will boot up to a passwordless root shell.
  • 4

  • Now issue the command passwd username *where “username” is the user for which you want to change the password.
  • Then you will be asked to give a new password:
Enter new UNIX password:

5

Explanation
The reason why this happens is that normally when a Linux system boots, the kernel is loaded first. After the kernel is loaded, it loads the ramdisk and gets ready for continuing the rest of the booting. Once it is ready, it runs the init command (usually located at /sbin/init) which would run the rest of the system. When you pass init=/bin/bash to the kernel, it will not load /sbin/init file for booting, instead it will load /bin/bash file which starts the bash shell with the root user’s power (because the kernel itself called it) and hence that prompt would allow you to change the root user’s password. Actually, this prompt had more power than anything else on Linux because it is running with all the privileges of the system.

References
https://wiki.archlinux.org/index.php/Reset_root_password


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads