Home  >  Article  >  Computer Tutorials  >  If you forget your Linux password, you can retrieve it like this

If you forget your Linux password, you can retrieve it like this

王林
王林forward
2024-02-19 15:40:03912browse

If you forget your Linux password, you can retrieve it like this

Forgetting your password is one of the situations we often encounter, whether it is on the operating system, website account, mobile phone, email or other channels. Sometimes if a password needs to meet certain complexity requirements, such as containing uppercase letters, lowercase letters, numbers, and special characters, and is long enough, it can become difficult to remember the password, and over time, it can be easy to forget. If you forget your password, you can generally use your mobile phone number to retrieve it. However, if the operating system forgets it, it will be a bit troublesome. Here we will teach you how to retrieve the server password without reinstalling the system.

Ubuntu system forgotten password solution

Recovery mode and single-user mode processing can be used in Ubuntu systems:

Recovery Mode

To reset your Ubuntu system password, you can do it by following these steps: Restart your computer and hold down the Shift key to enter the GRUB menu. Select "Advanced options for Ubuntu" and enter "recovery mode". In recovery mode, select "root" mode and enter the command "passwd yourusername", where yourusername is your username. After entering the new password twice and restarting the system, you can log in using the new password.

Single user mode

When restarting the computer, hold down the Shift key to enter the GRUB menu. Select "Ubuntu, with Linux…" and press the e key to enter edit mode. Add the "recovery nomodeset" parameter at the end of the second to last line and press F10 to enter single-user mode. In single-user mode, run the command passwd yourusername to change the password, and then enter the new password twice. Restart the system and log in with the new password.

General methods for handling forgotten passwords in Linux systems

To restart the Linux system, press the "Shift" key or other designated keys on the keyboard to enter the boot menu. Different Linux distributions and versions may require different keystrokes. If the Shift key does not work, you can try multiple times.

In the boot menu, use the arrow keys to locate the entry labeled "Recovery Mode", "Repair" or similar options, and then press the "Enter" key to enter that mode.

After entering recovery mode, a privileged command line interface called "root shell" or "root console" will appear. On this interface, you can log in as the root user and perform operations that require privileged permissions.

4. In the root console, enter the following command to mount the system's root directory in writable mode:

mount -o remount,rw /

This command remounts the root file system in read-write mode so that you can modify files.

5. List all users to find the username whose password you want to reset. Enter the following command:

ls /home

This command will display the list of users that have been created on the system.

6. Select the username whose password you want to reset and run the following command to change the password. Replace "username" with the actual username you want to reset the password for:

passwd username

After executing this command, the system will ask you to enter a new password. Remember, when entering the password, no characters will be displayed. This is for Linux security reasons.

7. After entering the new password, follow the prompts to re-enter the same password for confirmation.

8. After changing the password, use the following command to remount the root file system in read-only mode to ensure system security:

mount -o remount,ro /

9. Enter the following command to restart the system:

reboot

The system will restart and load the normal login interface. Log in to your account using the new password you just set.

Finally, the specific performance of these steps may vary slightly depending on the Linux distribution and version. If you encounter difficulties or are not sure how to perform certain steps, you need to refer to the documentation of the Linux distribution you are using or the relevant forums for help. Additionally, always ensure that you have sufficient authority and understanding before performing such operations to avoid accidental or irreversible damage.

The above is the detailed content of If you forget your Linux password, you can retrieve it like this. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete