Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BtbN opened this issue Apr 14, 2019 · 19 comments
Closed
Labels

Comments

@BtbN
Copy link

BtbN commented Apr 14, 2019

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.

@therealkenc
Copy link
Collaborator

therealkenc commented Apr 14, 2019

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.

@hermanocabral
Copy link

hermanocabral commented Apr 27, 2019

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

@KaOzPoNs
Copy link

KaOzPoNs commented Jun 20, 2019

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: Bob1000:1000 Bob

That 1000 is the Uid

I hope this help to someone.

@merkuriy
Copy link

merkuriy commented Aug 20, 2019

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.

@anaisbetts
Copy link

anaisbetts commented Sep 4, 2019

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)

@thisguychris
Copy link

thisguychris commented Jan 21, 2020

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. 🙏🏻

@BtbN
Copy link
Author

BtbN commented Jan 21, 2020

Looks great to me!

@BtbN BtbN closed this as completed Jan 21, 2020
@therealkenc
Copy link
Collaborator

therealkenc commented Jan 21, 2020

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

@shinji257
Copy link

shinji257 commented May 26, 2020

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.

@BtbN
Copy link
Author

BtbN commented May 27, 2020

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.

@ArthurYdalgo
Copy link

ArthurYdalgo commented May 30, 2020

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

@alan23273850
Copy link

alan23273850 commented May 31, 2020

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!

@data-pata
Copy link

data-pata commented Jun 5, 2020

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!

@kre75rub
Copy link

kre75rub commented Jul 2, 2020

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.

@richardso21
Copy link

richardso21 commented Jul 7, 2020

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.

@codeacade
Copy link

codeacade commented Aug 12, 2020

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)

@CompSciMaj13
Copy link

CompSciMaj13 commented Aug 12, 2020

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)

@calbraz
Copy link

calbraz commented Aug 13, 2020

ubuntu2004 config --default-user user_name

@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, @codeacade, if ran from Ubuntu shell, ubuntu config command is not a recognized command. Wonder why..

@benhillis
Copy link
Member

benhillis commented Aug 13, 2020

@calbraz - it's not.

/etc/wsl.conf

[user]
default=username

@microsoft microsoft locked and limited conversation to collaborators Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests