How to change default user in WSL Ubuntu bash on Windows 10

Now that LxRun.exe is deprecated, if you install Ubuntu from the Windows store the command you will need to run at a windows command prompt is

ubuntu config --default-user <username>

(Note: depending on which version you installed this could be ubuntu1804.exe or ubuntu2004.exe)

Restart LxssManager service

sc stop LxssManager
sc start LxssManager

The top answer (ubuntu config --default-user root) is currently correct for the default instance. But if you have multiple instances, you need to work slightly harder:

Inside the instance, as root, create/edit /etc/wsl.conf and add these lines:

[user]
default=username

Then close it, run wsl --terminate <distro name> in PowerShell, and restart it.

That's from an issue in the WSL repo. The registry hack answer is also in there, but /etc/wsl.conf is now officially the supported solution.