-
Notifications
You must be signed in to change notification settings - Fork 814
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
Comments
Probably. To the extent these registry entries continue to exist under the present WSL model, anyway. Or, to the extent So I guess a concrete ask would be for something like:
Fair enough. Someone motivated could probably do a short powershell script to that effect. |
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:
|
Hi there! I think that I found the solution for this... As BtbN said, the relevant registry key must be changed...
Where is the name of the distribution (while using wsl --Import ). Note: To find the Uid just write "cat /etc/passwd | grep " For example: cat /etc/passwd | grep Bob That 1000 is the Uid I hope this help to someone. |
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-SetDefaultUserMy 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:
Remove function:
Single-line command with call and remove functionFunction 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 |
imho this should be moved into |
As of build no. 18980 You can set the default user via editing [user]
default=username No need for registry hacks or DistroLauncher anymore. I believe @BtbN / @therealkenc we can close this now. 🙏🏻 |
Looks great to me! |
Call it fixedinsiders; it was a legit feature request just never got categorized as such. |
This is an old thread but I'm surprised that for changing the default user no one ever thought about |
Very first sentence of the report:
|
You just saved my day, sir |
This solution also works for me! Thank @thisguychris very much! |
edit: Thanks by the way!
|
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 |
Actually for latest ubuntu versions this is (this command should be run from Windows level - CMD or PowerShell window) |
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. |
@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, |
@calbraz - it's not. /etc/wsl.conf
|
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.
The text was updated successfully, but these errors were encountered: