Score:1

Ubuntu on WSL started defaulting to root user

et flag

Yesterday, all was well. This afternoon I restarted my computer after some file downloads from my class bogged down my laptop. Upon restarting and opening Ubuntu, it defaulted to root@<mysystem>:~#. I can su <username> but it then defaults that user to the /root directory. Even under that user, commands like explorer.exe and code . to open VSCode do not work.

I am running Ubuntu on WSL 1

hr flag
Are you running a full Ubuntu installation - or is it Windows Subsystem for Linux (WSL)?
macky avatar
et flag
Yes, I am running Ubuntu on WSL.1
Score:2
vn flag

Troubleshooting steps that I can think of (and I'd be trying if this happened):

  • Does your normal user's /home/<username> directory still exists?

  • If so, does everything look "normal" inside it when viewed as the root user? Among other things, are the files inside it owned by your normal user or by root? If they are owned by root, then that could be an issue we'll need to work on further.

  • Start Ubuntu with:

    wsl ~ -u <Ubuntu_username> -e bash --noprofile --norc
    

    If that logs you in as that user (your prompt will be different), then there's likely something wrong in your ~/.bashrc (although it could be a different file).

  • If the above command doesn't work, add any error messages or results to your question in an edit. Then check to see if the user exists in the /etc/passwd file.

  • Side-note: The reason that explorer.exe doesn't work is likely that su <username> sets the user's path via "Linux" methods, but when you start Ubuntu on WSL "normally", WSL adds the Windows path to the Linux path. After using su <user>, try running /mnt/c/WINDOWS/explorer.exe - I'm expecting that it will work, but confirm the results (either way) in a comment or (preferably) edit to your question.

  • You mention in the comments WSL1, which uses a different filesystem than WSL2, and it's a bit more "fragile". You mention that you were having an issue with a file download when you had to restart. Is there any chance you were trying to download the files directly into C:\Users\<youruser>\AppData\Local\Packages\... to get them into Ubuntu? If so, that might have corrupted the home directory. If you used \\wsl.localhost\Ubuntu or \\wsl$\Ubuntu then that shouldn't be a problem.

    I'm not sure I want to jump to that conclusion and start "recovery", though, unless we truly fail with all of the above diagnostics. But do let me know if there's a chance you used the AppData path to access WSL1 so we can keep that in mind if we need to troubleshoot further.

Score:2
tj flag

I faced the same problem after I moved the WSL from C drive to D drive. This was easily fixed using -

ubuntu config --default-user <your-username>

Hope this helps.

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.