Skip to content

Impossible to set default user of distribution installed via wsl --import on 1903 #3974

Description

@BtbN

Windows Version 10.0.18362.30 (1903)

The only way that's left to set the default user of a distribution is via its command line utility (ubuntu.exe for example).
However, for Distributions installed via "wsl --import", no such command exists.

Since lxrun does not exist anymore, there appears to be no way to change the default user.

I tried manually setting it via WslConfigureDistribution from wslapi.dll, but all I'm getting back is an Access Denied error code.

Edit:
I found the relevant registry key at
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{MY-UUID}
Where I could set DefaultUid to the desired value.
Still, there should be a command for this in wsl.exe or at least somewhere at all.

Activity

  1. therealkenc commented on Apr 14, 2019

    @therealkenc

    I found the relevant registry key at
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss{MY-UUID}

    ...\Lxss\{DISTRO-UUID}\DefaultUid, yes.

    Still, there should be a command for this in wsl.exe or at least somewhere at all.

    Probably. To the extent these registry entries continue to exist under the present WSL model, anyway. Or, to the extent --export isn't bundling up (and --import isn't restoring) everything PackageFamilyName related including the launcher.

    So I guess a concrete ask would be for something like:

    wsl.exe --setdefaultuid DistributionName uid
    

    Fair enough. Someone motivated could probably do a short powershell script to that effect.

  2. hermanocabral commented on Apr 27, 2019

    @hermanocabral

    I had the same issue after importing Ubuntu 18.04 and until the import/export is fixed (IMHO the problem lies there) you can use the LxRunOffline tool to set the default user:

    LxRunOffline.exe set-uid -n Name_of_Distro -v user_UID

  3. kaozpons117 commented on Jun 20, 2019

    @kaozpons117

    Hi there! I think that I found the solution for this...

    As BtbN said, the relevant registry key must be changed...
    If you don't want to install LxRunOffline or some other tool... I can do the job with this command in the PowerShell:

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

    Where is the name of the distribution (while using wsl --Import ).
    and the "- Value 1000" is the Uid of the user that you want to change.

    Note: To find the Uid just write "cat /etc/passwd | grep "

    For example: cat /etc/passwd | grep Bob
    Result: Bob:x:1000:1000 Bob

    That 1000 is the Uid

    I hope this help to someone.

  4. merkuriy commented on Aug 20, 2019

    @merkuriy

    Thanks to KaOzPoNs for the proposed manual method! Next, my additions.

    Get UID value by specific distro and user.

    wsl -d <DistroName> -u <UserName> -e id -u

    Command WSL-SetDefaultUser

    My PowerSheell function for set default user by distro name and user name. It works both for official distributions (from the MS Store), and for any custom distros.

    Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };

    Using:

    WSL-SetDefaultUser <DistroName> <UserName>

    Example using:

    WSL-SetDefaultUser ubuntu-19-04-server merkuriy
    

    Remove function:

    Remove-Item Function:WSL-SetDefaultUser
    

    Single-line command with call and remove function

    Function WSL-SetDefaultUser ($distro="<DistroName>", $user="<UserName>") { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); }; WSL-SetDefaultUser; Remove-Item Function:WSL-SetDefaultUser;

    Replace <DistroName> and <UserName> inserts at the begin of the command.

  5. anaisbetts commented on Sep 4, 2019

    @anaisbetts

    imho this should be moved into wsl.exe, it's the only configuration option where you still have to use DistroLauncher (or manually hack the registry)

  6. chiefjester commented on Jan 21, 2020

    @chiefjester

    As of build no. 18980

    You can set the default user via editing /etc/wsl.conf.

    [user]
    default=username

    No need for registry hacks or DistroLauncher anymore.

    I believe BtbN / therealkenc we can close this now. 🙏🏻

  7. BtbN commented on Jan 21, 2020

    @BtbN
    Author

    Looks great to me!

  8. therealkenc commented on Jan 21, 2020

    @therealkenc

    Call it fixedinsiders; it was a legit feature request just never got categorized as such.

  9. shinji257 commented on May 26, 2020

    @shinji257

    This is an old thread but I'm surprised that for changing the default user no one ever thought about ubuntu config --default-user username. This still works even with WSL 2.

  10. BtbN commented on May 27, 2020

    @BtbN
    Author

    Very first sentence of the report:

    The only way that's left to set the default user of a distribution is via its command line utility (ubuntu.exe for example).
    However, for Distributions installed via "wsl --import", no such command exists.

  11. ArthurYdalgo commented on May 30, 2020

    @ArthurYdalgo

    Thanks to KaOzPoNs for the proposed manual method! Next, my additions.

    Get UID value by specific distro and user.

    wsl -d <DistroName> -u <UserName> -e id -u

    Command WSL-SetDefaultUser

    My PowerSheell function for set default user by distro name and user name. It works both for official distributions (from the MS Store), and for any custom distros.

    Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };

    Using:

    WSL-SetDefaultUser <DistroName> <UserName>

    Example using:

    WSL-SetDefaultUser ubuntu-19-04-server merkuriy
    

    Remove function:

    Remove-Item Function:WSL-SetDefaultUser
    

    Single-line command with call and remove function

    Function WSL-SetDefaultUser ($distro="<DistroName>", $user="<UserName>") { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); }; WSL-SetDefaultUser; Remove-Item Function:WSL-SetDefaultUser;

    Replace <DistroName> and <UserName> inserts at the begin of the command.

    You just saved my day, sir

  12. alan23273850 commented on May 31, 2020

    @alan23273850

    As of build no. 18980

    You can set the default user via editing /etc/wsl.conf.

    [user]
    default=username

    No need for registry hacks or DistroLauncher anymore.

    I believe BtbN / therealkenc we can close this now. 🙏🏻

    This solution also works for me! Thank ThisGuyChris very much!

  13. data-pata commented on Jun 5, 2020

    @data-pata

    edit: Thanks by the way!
    Merkuriy and KaOzPoNz solution worked but not:

    As of build no. 18980
    You can set the default user via editing /etc/wsl.conf.

    [user]
    default=username

    No need for registry hacks or DistroLauncher anymore.
    I believe BtbN / therealkenc we can close this now. 🙏🏻

    This solution also works for me! Thank ThisGuyChris very much!

  14. kre75rub commented on Jul 2, 2020

    @kre75rub

    As of build no. 18980
    You can set the default user via editing /etc/wsl.conf.

    [user]
    default=username

    No need for registry hacks or DistroLauncher anymore.
    I believe BtbN / therealkenc we can close this now. 🙏🏻

    Might be obvious but, to save some people a bit of headache, I want to point out, that it is important to --terminate the running distro, in order to have this work.

  15. richardso21 commented on Jul 7, 2020

    @richardso21

    As of build no. 18980
    You can set the default user via editing /etc/wsl.conf.

    [user]
    default=username

    No need for registry hacks or DistroLauncher anymore.
    I believe BtbN / therealkenc we can close this now. 🙏🏻

    Might be obvious but, to save some people a bit of headache, I want to point out, that it is important to --terminate the running distro, in order to have this work.

    Can confirm that running wsl.exe --terminate <distro name> resolved it for me. Or, you can wait out a few minutes.

  16. codeacade commented on Aug 12, 2020

    @codeacade

    This is an old thread but I'm surprised that for changing the default user no one ever thought about ubuntu config --default-user username. This still works even with WSL 2.

    Actually for latest ubuntu versions this is ubuntu[version] config --default-user user_name
    For example ubuntu2004 config --default-user user_name

    (this command should be run from Windows level - CMD or PowerShell window)

  17. CompSciMaj13 commented on Aug 12, 2020

    @CompSciMaj13

    I ran into quite a few issues when converting from WSL 1 to WSL 2 that relates to this ticket. I detailed my environment and the journey I took to work around them in the following comment.

    #4102 (comment)

  18. calbraz commented on Aug 13, 2020

    @calbraz

    ubuntu2004 config --default-user user_name

    code (@codeacade), it seems the cleanest fix. I have tried ThisGuyChris solution, which has worked, once you terminate wsl. This was also described in FAQ session of the page containing the scrip that automates this operation: https://github.com/pxlrbt/move-wsl

    BTW, code (@codeacade), if ran from Ubuntu shell, ubuntu config command is not a recognized command. Wonder why..

  19. benhillis commented on Aug 13, 2020

    @benhillis
    Member

    calbraz - it's not.

    /etc/wsl.conf

    [user]
    default=username
    
  20. locked and limited conversation to collaborators on Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions