Repository navigation
Impossible to set default user of distribution installed via wsl --import on 1903 #3974
Description
Activity
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
--exportisn't bundling up (and--importisn't restoring) everythingPackageFamilyNamerelated including the launcher.So I guess a concrete ask would be for something like:
wsl.exe --setdefaultuid DistributionName uidFair 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:
LxRunOffline.exe set-uid -n Name_of_Distro -v user_UIDReacted by Kari SöderholmHi 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 1000Where 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 BobThat 1000 is the Uid
I hope this help to someone.
Reacted by therealkenc, Eric Blade, chadrien, Matt Hoover, Uriy Efremochkin, Cretezy, Sean Fang, derekxia1988, Daniel, Hsn723 and 35 moreReacted by Caio Farias and Nate RyallReacted by Tom, Matthew, Hugo Fonseca, Rudi Poepsel Lemaitre, Victor Huang, Jamie Reid, Em Jones, Marisa Heit, José Proença, Caio Farias and 3 moreThanks 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 merkuriyRemove 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.Reacted by Manuel Jenny, Uriy Efremochkin, Yannick, Nicolas Tsagarides, Eduardo Pereira, Cem Sancak, Stefan Dobrovolny, Daryl Liu, Daniel, flow7952 and 44 moreReacted by Arthur Ydalgo, Silun and Mohammadreza GhofraniReacted by Chip Locke, Olivier Jacques, Rafael Bernardelli, Noah Worley, Arthur Ydalgo, Silun, Sravanth C., Velocet and Juliano Gracianoimho 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)Reacted by Dan Maher, Daryl Liu, Edward Brown, Artem Rumyantsev, Igor Gerets, Brian McKenna, Railly Koeiman, Thomas Meckel, Nano, Thell 'Bo' Fowler and 2 moreAs 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. 🙏🏻
Reacted by therealkenc, mitchell-wong-imprivata, Shahaed Hasan, Andy Li, Jimmy Yen, Ranvir Singh, Dennis Koch, Thomas Meckel, Radoslav Stoyanov, Bharat Kambalur and 11 moreReacted by Wei-Lun TsaiLooks great to me!
Reacted by ^_^Call it fixedinsiders; it was a legit feature request just never got categorized as such.
Reacted by ^_^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.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.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 merkuriyRemove function:
Remove-Item Function:WSL-SetDefaultUserSingle-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
Reacted by Mohamed YousifAs 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!
Reacted by ^_^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!
Reacted by Kari SöderholmAs 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.
Reacted by Richard So and João Paulo Pozo LindgrenAs 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.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 exampleubuntu2004 config --default-user user_name(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.
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 configcommand is not a recognized command. Wonder why..- locked and limited conversation to collaborators
on Aug 13, 2020
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.