WSL2 forgot user password

Step 1: Switch the default user to root

Start the command prompt in Windows and enter:

ubuntu2004 config --default-user root

This has switched the default user of my ubuntu20.04 to root.
The first symbol of the command may be different in different WSL versions. The difference is as follows:

insert image description here

Step 2: Reset user password

Type in WSL

passwd username

This username is my own username. I wrote the username here for invisibility
and then received instructions to enter the password and confirm the password.

Enter the password and confirm it

Step 3: Switch back to normal user

Do it again like step 1, except that the user is no longer root but his own username

ubuntu2004 config --default-user username

Guess you like

Origin blog.csdn.net/qq_44421796/article/details/131735625