Score:5

How do I change the default user that signs in on WSL?

us flag

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:

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

This is the wsl.conf file

Note: also I am not able to run WSL commands

wsl not found

in flag
[This answer](https://askubuntu.com/a/1209881/1222991) may be the one you’re looking for
Score:4
vn flag

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.

Shayc20 avatar
us flag
Thank you so much, and yeah my pc decided to restart when I was setting that up, okay so where exactly does this file go? (Where is /etc) or do I just use that path from the root directory?
Shayc20 avatar
us flag
I tried that, and it didn't work.. Ive updated Post
NotTheDr01ds avatar
vn flag
The `wsl` command is typically run from *outside* the WSL instance -- From PowerShell or CMD. I've updated my answer to make that more clear. The `/etc/wsl.conf` won't take effect until you really do terminate it, so that's hopefully why you aren't seeing the new user. If you *do* need to run the `wsl` command from inside Ubuntu, use `wsl.exe`, since it's a Windows executable.
NotTheDr01ds avatar
vn flag
@Shayc20 Sorry, I forgot to tag you in my response yesterday, so you may not have been notified.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.