Score:2

How to return to default user after switching to root in Ubuntu on WSL?

re flag

I am using WSL on Windows 11 with Ubuntu 20.04 LTS (Focal Fossa).

During the installation process, I think I entered the command ubuntu --install (in VSCode), but I ran into an issue during the installation. The terminal opened, asking for a Linux user and password, but then it closed as some other application started or something.

Since I never got the chance to set my default user's password, I opened CMD, and, if I remember correctly, used the command ubuntu config --default-user root. Then I returned to the Ubuntu shell and entered a command to reset my Linux password.

At this point I had not even used my VSCode. However, when I open VSCode, it still seems to be in the root user's account.

I used mkdir to create a folder without realizing I was still in root, as shown below:

root@Lokrheim:~/folder# 

When I type exit, the shell just closes, as if it is exiting the application rather than the root user's login. No matter what I do, my VSCode still remains as a root user.

How can I access my non-root user in Ubuntu on WSL?

Score:2
vn flag

there was an issue upon restarting as the shell had opened asking for a Linux user and password but the shell closed as some other application started or something

It sounds like you have an aborted installation, which probably left you without a default user at all. In this case, WSL defaults to using the root user (regardless of the distribution).

Option 1: Reinstall Ubuntu on WSL

If you've just recently installed and don't have any files that you don't mind losing in Ubuntu, then the best solution is going to be to simply reinstall the distribution so that it completes properly.

To do so, open a regular (non-Admin) PowerShell terminal, and ...

wsl --unregister Ubuntu
ubuntu.exe

(Side-note: If this was Ubuntu 22.04, I'd recommend using either ubuntu.exe install --gui=none or ubuntu2204.exe install --gui=none as per this answer.)

That will pretty-quickly complete the installation (since it doesn't actually have to re-download the Store package) and get you back to the point where it asks for a default username and password.

Option 2: Recreate user manually

If you do have files and need to recover without a reinstall, see this answer and look for the section on "Creating a new "default" WSL user without reinstalling". Also use the next step (Setting the default WSL user) to reset the default after creating one.

I sit in a Tesla and translated this thread with Ai:

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.