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.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityNow 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
)
If you're using WSL2, you're done.
For WSL1, you'll need to also 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.
wsl --export
and wsl --import
Mar 24, 2021 at 15:45
root
to my own user and this was the answer.
Jul 11, 2021 at 5:01
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>
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>
If you're running Ubuntu 18.04 from the Microsoft Store, the command (powershell or cmd) will be:
ubuntu1804 config --default-user <username>
Old question that got bumped today, but the answers need updating and consolidating to be current (and correct).
There are two parts to the question, and every answer here so far just covers one or the other.
First question:
How can I change the user name of the user I'm logged in as?
As @PJ127 correctly pointed out, the first step is to actually change the username within Ubuntu. This can most easily be done (now, in 2021) by exiting WSL and starting PowerShell, then:
wsl -l -v
wsl --terminate <distro> # <distro> from the previous command
wsl -u root -d <distro> # "-d <distro>" is only needed for non-default instances
# Now from in WSL
usermod -l newname oldname
# Optionally change the home directory name to match
usermod -d /home/doug -m doug
# Optionally change the group name to match
groupmod -n newname oldname
Then there's the second part of the question, which is what most of the answers here attempt to cover:
When I open bash it automatically logs me in with my current user
There are multiple ways of doing this, but the Microsoft recommended/documented method in 2021 is as @Jacktose answered:
In your WSL instance, sudo editor /etc/wsl.conf
with the following contents:
[user]
default=username
Exit, then from PowerShell, wsl --terminate <distro name>
and restart WSL.
While the ubuntu.exe --config
method will work, there are two problems:
It's not always "ubuntu.exe". The name of the executable (technically "app execution alias") depends on which version you installed from the Store. Ubuntu has come in multiple Store packages over the years. There's a package for each supported release (e.g. ubuntu2004.exe
, etc.) and one for the "current" version (ubuntu.exe
). And while this is Ask Ubuntu, it also could be alpine.exe
, etc. if you are using a different distribution.
It also, as has been pointed out in other answers, does not work if you have more than one instance installed (which is a great feature of WSL). It will only work for the first, store-installed instance.
Then, of course, there are registry-based methods of changing the default name, but since we have safer, supported methods let's not even cover those here. :-)
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
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
sudo kill processId
Jun 25, 2021 at 16:46
Use wsl --list command to see what WSL distribution you have installed. It may return Ubuntu-22.04 or some other version you may have installed. Alternatively you can run the following from WSL Ubuntu terminal session to get your Ubuntu version:
grep "DISTRIB_RELEASE=" /etc/lsb-release | grep -E [0-9]{2}.[0-9]{2} -o
Having Ubuntu version clarified run the command below from Windows CMD to set your default user, making sure that replacing 2204 to the specific version you have (obtained using commands above):
ubuntu2204 config --default-user <username>
ubuntu2204
for the latest release, then that should be a simple edit to the existing answer. If you'd like to make that edit, I'd be happy to approve it for you. Thanks!
Dec 2, 2022 at 12:27
ubuntu2004
command becomes available for use:ubuntu2004 config --default-user robert
/etc/wsl.conf
file