How do I change the default user that signs in on WSL?
I'm running Ubuntu terminal on windows with WSL, Every time I launch the terminal it signs me in as the root user. I've created a new user and given them root privileges so that I can code easier. How do I change the default user that gets signed in?
This is what I see when I launch:
After running su shayc
I can get to my user, but how do I avoid doing this
every time?
**UPDATE: ** I've tried setting a default user in /etc/wsl.conf
Note: also I am not able to run WSL commands
A few things to look at here. First, when you ran Ubuntu for the first time after installing on WSL, it should have gone through a "configuration" step where it asked you to create a username and password. This user would be the "default user" that should be used when running. If the instance is running with "root" as the default user, then that could signal an error in the configuration (and from the comments, this appears to be what happened).
That's not a huge deal, honestly. You've done the right thing in creating a new user. Just that it shouldn't have been necessary.
As for setting that new user as default, there are at least two possible paths:
Option 1: wsl.conf
The current Microsoft recommended way 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.
Exit your instance, issue a wsl --terminate Ubuntu
(assuming your instance name is "Ubuntu", which you can confirm with wsl -l -v
) or wsl --shutdown
(from PowerShell or CMD), and restart.
Option 2: "Reset" the instance back to the configuration stage
Note that this is a destructive operation. If you don't have any work inside the instance that you can't recovery easily, then you can easily reset the instance back to the initial state. This is because WSL leaves the original rootfs for any distribution a hidden directory under C:\ProgramData
.
You can always back up the old instance before doing this "just in case". The commands (again, all from PowerShell or CMD) should look something like:
wsl --export Ubuntu "2021-11-21 Ubuntu WSL Backup.tar"
Then (and this is the destructive part):
wsl --unregister Ubuntu
Then rerun the "App" with ubuntu.exe
(or, if you installed a version-specific app from the Store, it may be ubuntu2004.exe
).
At that point, the configuration step will re-run, asking for the default username and password.