0

I've imported a WSL image I had exported from WSL previously (wsl --import UbuntuTest ./UbuntuImport .\UbuntuSnapshot201011).

My distro has been correctly installed as UbuntuTest. However, when I log into it with wsl -d UbuntuTest the default user is root, and not roemerco. I would like to change it, so that I can login just with wsl -d UbuntuTest not needing the CLI option -u roemerco in addition.

Apparently, for many users, it's possible to change default users by running a command like ubuntu config --default-user <username> (see How to change default user in WSL Ubuntu bash on Windows 10). However, this doesn't work in my case. Neither on CMD nor Powershell is ubuntu or ubuntu2004 a recognised command. This may be, because I haven't installed the distro through the Microsoft Store.

Does anyone have any thoughts? I tried to find stuff in the WSL docu, but couldn't find anything about it. Is this a missing feature or bug?

  • Yes it does, the distro works properly. It's just that it uses root by default and I don't know how to change it. The ubuntu2004 command doesn't exist. – Cornelius Roemer Oct 13 '20 at 19:17
  • @steeldriver I've tried that already both from CMD and PS, neither works: 'UbuntuTest' is not recognized as an internal or external command, operable program or batch file. and UbuntuTest : The term 'UbuntuTest' is not recognized as the name of a cmdlet, function, script file, etc. – Cornelius Roemer Oct 13 '20 at 20:20

1 Answers1

3

Actually there's a much discussed issue for exactly my problem on WSL Github. There are two methods to solve the problem: a) registry hack, b) editing a config file. The powershell registry hack worked for me:

Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName `
| Where-Object -Property DistributionName -eq UbuntuTest `
| Set-ItemProperty -Name DefaultUid -Value 1000

Replace UbuntuTest with your respective distro name.