3

I'm trying to move my WSL2 "distribution" to another hard drive with more space. I've performed the following:

wsl --export Ubuntu-20.04 ubuntu-20_04-export.tar
wsl --import Ubuntu-20.04-reimported D:\tools\wsl-ubuntu-20_04 .\ubuntu-20_04-export.tar

and I've changed my WinTerm configuration to set the new distro as the default profile. I've also set the distro as the default distro with wsl -s. And I've unregistered the old distro. But when I start up the new WSL distro in WinTerm, it now signs me in as root. As in this question, I've tried to run the following:

ubuntu2004.exe config --default-user <existing-user-name>

But new sessions started with WinTerm still start as root by default. ubuntu2004.exe doesn't seem to affect the new distro but instead installs yet another distro in order to set the default user there. The following works fine with the new distro:

wsl -u <existing-user-name>

But how do I change the default user of the new distro?

1
  • One of the problems caused by this is that my VS Code WSL extension connecting to WSL as root and saving new files and such as root.
    – xdhmoore
    Dec 6, 2020 at 2:51

1 Answer 1

4

A few weeks later, I found a duplicate question on StackOverflow (not sure of the protocol for cross-site duplicates...).

The answer that worked for me was adding the following to my distribution's /etc/wsl.conf:

[user]
default=yourusername
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.