A few things to look at here. First, when you ran Ubuntu for the first time after installing on WSL, it should have gone through a "configuration" step where it asked you to create a username and password. This user would be the "default user" that should be used when running. If the instance is running with "root" as the default user, then that could signal an error in the configuration (and from the comments, this appears to be what happened).
That's not a huge deal, honestly. You've done the right thing in creating a new user. Just that it shouldn't have been necessary.
As for setting that new user as default, there are at least two possible paths:
Option 1: wsl.conf
The current Microsoft recommended way is to create a /etc/wsl.conf
in the instance with the following setting:
[user]
default=username
Changing, of course, username to be your default username.
Exit your instance, issue a wsl --terminate Ubuntu
(assuming your instance name is "Ubuntu", which you can confirm with wsl -l -v
) or wsl --shutdown
(from PowerShell or CMD), and restart.
Option 2: "Reset" the instance back to the configuration stage
Note that this is a destructive operation. If you don't have any work inside the instance that you can't recovery easily, then you can easily reset the instance back to the initial state. This is because WSL leaves the original rootfs for any distribution a hidden directory under C:\ProgramData
.
You can always back up the old instance before doing this "just in case". The commands (again, all from PowerShell or CMD) should look something like:
wsl --export Ubuntu "2021-11-21 Ubuntu WSL Backup.tar"
Then (and this is the destructive part):
wsl --unregister Ubuntu
Then rerun the "App" with ubuntu.exe
(or, if you installed a version-specific app from the Store, it may be ubuntu2004.exe
).
At that point, the configuration step will re-run, asking for the default username and password.