WSL Distro – Set Default User for Manually Installed

linuxuser-accountswindowswindows-subsystem-for-linux

I have cloned a WSL distro using wsl --export and wsl --import, but now, running wsl newdistro always logs me in as root. I understand that the lxrun command is deprecated and want to avoid it. The docs recommend using distroname.exe config, but that doesn't work, since this one doesn't have a corresponding executable.

Best Answer

As of the time of this writing, there are at least three (let's call it 3.5) different methods of changing/setting the default user in a WSL instance. While the two that have already been mentioned still work, there is a Microsoft recommended way to do it that hasn't been mentioned yet in this question.

Method 1 - /etc/wsl.conf

The current Microsoft recommended way of setting the username in an instance 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.

This is safer and less error-prone than the registry-based methods.

Method 2 - Registry Key

Setting the registry key per @harrymc's answer.

Method 3 - LxRunOffline

Using LxRunOffline to set the registry entry, as described in @Jaime's answer. Ultimately this has the same effect as Method 2.

Semi-method 4 - Runtime user selection via wsl commandline argument

The username can be selected when starting any WSL instance by:

wsl -u username or wsl -d distroname -u username, etc.

For instance, wsl -d Ubuntu -u root.

Related Question