天天看点

change or reset WSL passwordchange or reset WSL password

change or reset WSL password

To change or reset your password, open the Linux distribution and enter the command:

passwd

. You will be asked to enter your current password, then asked to enter your new password, and then to confirm your new password.

If you forgot the password for your Linux distribution:

  1. Open PowerShell and enter the root of your default WSL distribution using the command:

    wsl -u root

    If you need to update the forgotten password on a distribution that is not your default, use the command:

    wsl -d Debian -u root

    , replacing

    Debian

    with the name of your targeted distribution.
  2. Once your WSL distribution has been opened at the root level inside PowerShell, you can use this command to update your password:

    passwd <username>

    where

    <username>

    is the username of the account in the distribution whose password you've forgotten.
  3. You will be prompted to enter a new UNIX password and then confirm that password. Once you're told that the password has updated successfully, close WSL inside of PowerShell using the command:

    exit

    .

References

Best practices for setting up a WSL 2 development environment | Microsoft Docs