Open In App

How to Reset a Lost Password in Ubuntu and Other Linux Distributions

Last Updated : 04 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This article explains how to reset lost a password in a Linux distribution. If you have forgotten your Linux password, this article is undoubtedly for You. This guide uses Ubuntu 23.04, but the same method applies to other versions of Ubuntu and other Linux distributions.

Reset password using recovery mode.

Step 1: During startup, from the Grub menu select “Advanced options for Ubuntu”.

Screenshot-(18)

Selecting advanced options in the Grub menu

Step 2: In the next screen go to recovery mode.

Screenshot-(19)

Selecting recovery mode

Step 3: Choose “root Drop to root shell prompt” from the Recovery menu and press Enter.

Screenshot-(20)

Recovery menu

Step 4: Press Enter again to access the root shell prompt.

Screenshot-(21)

Step 5 :Next, proceed by entering the commands given below to reset the password.

  • To get write access to the root partition execute the below command.
mount -rw -o remount / 
  • If you don’t know your username, use the following command to list all users.
ls /home
  • Now to reset the password execute “passwd username”, your username should replace the username.
passwd username
  • Enter a new password and retype the new password to confirm it (Note: Linux does not display the password you typed, just type and press Enter)
New password:
Retype new password:
passwd: password updated successfully
  • Now you have successfully changed your password. Execute “reboot” to restart the system.
reboot

Step 6: Now you can log in to the system as normal with the new password.

Note : If the above method does not work, use the alternate method given below.

Alternate method to reset Linux password.

Step 1: From the Grub menu press “e” to edit commands before booting.

Screenshot-(24)

Unedited grub commands

Step 2: In the line starting with linux, edit ro to rw and append init=/bin/bash at the end of that line.

Screenshot-(25)

Edited grub commands

Step 3: Press Ctrl+X to boot into the root shell.

Step 4 :Next, proceed by entering the following commands to reset the password.

  • If you don’t know your username, use the following command to list all users.
ls /home

  • Now to reset the password execute “passwd username”, your username should replace the username.
passwd username

  • Enter a new password and retype the new password to confirm it (Note: Linux does not display the password you typed, just type and press Enter).
New password:
Retype new password:
passwd: password updated successfully

  • Now you have successfully changed your password. Execute the following command to restart the system.
/sbin/reboot -f

Screenshot-(28)

Commands to reset password

Now you can use the system with a new password.

Conclusion

in this article we discussed that how to reset a lost password in a Linux distribution, primarily Ubuntu 23.04 but applicable to other versions and distributions. It offers two methods: one via recovery mode and an alternative through editing boot commands. The concise, step-by-step instructions are accessible to all users and emphasize password security. This article serves as a valuable resource for those locked out of their Linux systems, ensuring they can regain access quickly and securely.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads