Open In App
Related Articles

Reset a lost Linux administrative password and Explanation

Improve Article
Improve
Save Article
Save
Like Article
Like

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
http://www.c-integration.com/blog/showpost.php/83-reset-linux-root-password-without-knowing-the-password

If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 08 May, 2019
Like Article
Save Article
Previous
Next
Similar Reads