50

I installed the WSL Bash on Windows 10 and set my user to e.g. 'abc' but now I want to change it to something else.

How can I change the user name of the user I'm logged in as?

When I open bash it automatically logs me in with my current user.

3
  • 1
    As of now, Ubuntu 20.04 is current. After its installed using WSL 2, the ubuntu2004 command becomes available for use: ubuntu2004 config --default-user robert – BSalita Jun 23 '20 at 11:18
  • For those who didn't installed via store (e.g via export/import): github.com/microsoft/WSL/issues/3974#issuecomment-576782860. Default user can be changed by creating a /etc/wsl.conf file – Sebastian Hoffmann Nov 3 '20 at 12:27
  • Thanks so much @SebastianHoffmann, this comment is what made me realise that it was all due to the import. Thought when I exported that everything would be an exact copy, but I guess not. – EmSixTeen Jan 21 at 13:17
48

Now that LxRun.exe is deprecated, if you install Ubuntu from the Windows store the command you will need is

ubuntu config --default-user <username>

Restart LxssManager service

sc stop LxssManager
sc start LxssManager
7
  • 3
    ubuntu might NOT be your default, it depends which version you installed so check the answers below, as mine is "ubuntu1804 config ..." – rmcsharry Apr 25 '19 at 11:01
  • 5
    ubuntu1804 config --default-user ... for me – masterxilo Jul 11 '19 at 18:13
  • Restarting the service was a must for me. Googled a few minutes before I found this, no one really mentions it. Thanks! – jValdron Sep 11 '19 at 11:39
  • 1
    Is there a way to do this same action but using the 'bash' command? – rmutalik Dec 2 '19 at 19:07
  • 1
    instead of setting the default user it opened bash for me. It does not seem to be working for some reason. I am on the latest release of Windows as of today – akxer Dec 4 '19 at 17:09
25

All other answers were helpful, but can be other scenarios too, follow here as per yours. Mine was Ubuntu 16.04, so I used the following:

ubuntu1604 config --default-user <username>

If you installed Ubuntu 18.04:

ubuntu1804 config --default-user <username>

If you used the default one, then:

ubuntu config --default-user <username>
3
  • Should this not change the current username to the username I provide in <username>? When I try this it just tells me the username I am providing does not exist. This is on 18.0.4 – wuno Apr 26 '19 at 17:09
  • U may want to use root as user?? – kakabali Jun 27 '19 at 3:50
  • 1
    this should be the ANSWER, today at 2020-02-15, this is the only option works. – Luke Feb 15 '20 at 2:24
13

You can change the default user for bash by running the following command in a normal command prompt (cmd.exe):

LxRun.exe /setdefaultuser <new_name>
13

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.

3
  • 3
    For the ones who have moved the distro file from C to other drive like me. This worked in a go. – Asif Ali Dec 17 '20 at 8:41
  • 2
    This should be the accepted answer as this also works for custom installed distributions. – papercrane Jan 29 at 19:22
  • This works for my distro that was moved to another drive using wsl --export and wsl --import – Constructor Mar 24 at 15:45
12

If you're running Ubuntu 18.04 from the Microsoft Store, the command (powershell or cmd) will be:

ubuntu1804 config --default-user <username>
3

In CMD

See which distros you have installed wslconfig /l

I have Ubuntu and I wanted to set the default user to root ubuntu config --default-user root

Documentation: https://docs.microsoft.com/en-us/windows/wsl/user-support

0
0

ubuntu was not recognized by cmd.exe (Windows 10 / WSL Ubuntu 20.04), so the solutions above did not work for me.

What worked for me (from Windows terminal):

wsl.exe -u root
sudo usermod -l newUsername oldUsername
sudo usermod -d /home/newHomeDir -m newUsername

Not the answer you're looking for? Browse other questions tagged or ask your own question.