12

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" -~ 
6
  • Could be but there is no /setdefaultuser option :(
    – nowox
    Nov 9, 2017 at 12:32
  • @Ramhound: Why did you post a bounty when your own answer is accepted?
    – harrymc
    Jan 22, 2018 at 15:24
  • @Ramhound: I have the exact same question :)
    – nowox
    Jan 22, 2018 at 15:27
  • Does the accepted answer solve your issue?
    – nowox
    Jan 22, 2018 at 15:45
  • @Ramhound: What do you expect to achieve? Do you intend to never award the bounty, so nobody gets more than half the bounty and that also only if at least two voters happen to like the answer in the next 5-6 days? You know well that most voters will only look at the accepted answer and go away uninterested.
    – harrymc
    Jan 22, 2018 at 16:28

2 Answers 2

5

As of the time of this answer in 2021 (and for a few years now), 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 works in WSL1, WSL2, and regardless of the distribution name. It even works if the distribution wasn't installed from the Store.

16

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

5
  • I wouldn't have been able to find the documentation page if it wasn't for this answer so be sure to give it an upvote.
    – Ramhound
    Nov 9, 2017 at 16:10
  • How to set default user to root in WSL also submitted a similar answer but I didn't find it until after I submitted my answer.
    – Ramhound
    Nov 9, 2017 at 16:13
  • My answer was correct when it was submitted in 2017. According to the article it still is valid.
    – Ramhound
    Apr 25, 2019 at 11:02
  • This question and answer is from 2017. Newer versions of WSL instances would come with it own executable. In this case it’s specific to the instance from 2017 not 2018. The commands suggested are examples and specifically geared towards the author’s question. This answer is absolutely correct in the context of the author’s question
    – Ramhound
    Apr 25, 2019 at 11:07
  • Thanks for updating the question to reflect this, it will save people time explicitly stating that in the question as you have (especially noobs like me!). Thanks again!
    – rmcsharry
    Apr 25, 2019 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .