WSL – How to Change the Default User Name

windows-subsystem-for-linux

Many websites says I should use lxrun /setdefaultuser, but this command is deprecated:

C:\WINDOWS\system32>lxrun /setdefaultuser foo

Warning: lyrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.

How can I change the default username which is in my case root. I would like it to be the same username as I use with my Windows account.

Btw I am using mintty to run WSL:

%LOCALAPPDATA%\wsltty\bin\mintty.exe --WSL= -h err --configdir="%APPDATA%\wsltty" -~ 

Best Answer

Microsoft has documented how this is done on Fall Creators Update and later. The commands suggested are only an example and might vary based on the WSL instance you are using.

This question was asked in 2017, so the name of the WSL instance, might no longer be applicable to a newer version of Ubuntu WSL or if a different WSL distribution is being used. The commands that are suggested will work with any WSL distrubition on the Windows Store.

To see what commands are available for a particular distribution, run [distro.exe] /?.

For example, with Ubuntu installed:

C:> ubuntu.exe /?

enter image description here

Which means in order to change the default user to root in Ubuntu you would use the following command.

C:\> ubuntu config --default-user root

The documentation indicates the following:

enter image description here

Source: User Accounts and Permissions