Reset WSL Ubuntu user password

I suddenly forgot the WSL user password, which made it impossible to execute the sudo command and even download and install the software.

The solution is simple:

  1. Check your specific release version of WSL
    Win + Xshortcut keys to run the administrator modepowershell

    PS C:\WINDOWS\system32> wslconfig /l
    适用于 Linux 的 Windows 子系统分发版:
    docker-desktop-data (默认)
    docker-desktop
    Ubuntu
    

    The name of the distribution that I got here isUbuntu

  2. rootEnter the WSL system as the user

    PS C:\WINDOWS\system32> wsl.exe -d Ubuntu --user root
    Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)
    ...
    
  3. Reset user password (my username here is abc)

    root@FK-ThinkPad:/mnt/c/WINDOWS/system32# passwd abc
    New password:
    Retype new password:
    passwd: password updated successfully
    

Guess you like

Origin blog.csdn.net/qq12547345/article/details/128393171