-
Notifications
You must be signed in to change notification settings - Fork 849
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
WSL2 starting as root when starting with wsl.exe #4276
Comments
Which distro are you using? Is this a general problem across distros or just on one specific distro? If you switch back to WSL 1 and try to change the default user does that work? |
Ubuntu 18.04. I may add that this is imported WSL1 distro as WSL2 distro - I couldn't convert my old WSL1 distro. I'll have to check. |
I'm unable to repro your issue. I was able to set the default user using |
Ok, so this is how it went:
|
To resolve your immediate issue please see issue #3974 .
|
Yup, that worked, but why setting user doesn't do anything, without any error? |
At the time of writing this |
@Aulos I still have the Ctrl-C issue you described:
Did you figure out how to fix the Ctrl-C issue? I have successfully changed the default user via RegEdit. I did the same as you: |
I have recently added the ability to specify the default user in the /etc/wsl.conf file. That change is making its way to Insider builds. |
Should not that default user option be in |
@Biswa96 - .wslconfig is for global settings, /etc/wsl.conf is per-distro settings. |
Turns out the Ctrl-C issue I was seeing was due to an unrelated WSL bug: Windows interop being broken. Pengwin has a |
For anyone else wondering how the default user specification in wsl.conf as implemented by @benhillis works, see https://docs.microsoft.com/en-us/windows/wsl/release-notes#build-18980
You will probably have to |
It may should mentioned that the /etc/wsl.conf file needs to be created manually. This fixed it! thx! |
For WSL2 And did wsl.exe --shutdown Still logging in using zealous@Desktop <distro_name>.exe config --default-user root |
Not Ubuntu-20.04.exe
|
Still not working, Command not found. I doubt is it because I have installed distro manually ? And not from Windows Store |
Just to add a different context : |
for reference this approach can be used to fix when you mess up something with the root, like introducing the syntax error in the sudoers file. if you have few distros you can easily find to see which one is yours. Open registry edit and navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss{DISTRO-UUID. Please be careful when editing registry keys! |
To accomplish this feature please add this section to your
Replace with your Linux username. Here's a link to the docs: |
i know it's mentioned but that didn't work for me @craigloewen-msft |
Please make sure you are using Windows 10 Build 19041 or higher to use that feature. |
it works,thank you |
I report this issue with Fedora distro I installed yesterday from the store. Ask for change of default password for root never accepted any password I typed. Closed an open the session. Already in root. Later let me to change the password. But always in root. Different from the other distros I installed. Ubuntu, Pengwin, Debian. I think is a theme with the username cannot be the same with windows. |
I had the same issue and it is caused by a typo. instead |
As of 8/1/2021, with windows 11 and wsl2, this issue still exists. Exported Ubuntu. Imported it back and it goes straight to root. I did make the registry key change and this resolved it for me. |
This issue has nothing to do with import. |
in windows 11, wsl -d xxxx -u root |
works, thank you |
Same in 2022... works for me! Thanks! |
I also use this command. It's in my restore script for restoring a WSL2 backup. See the last line.. YOURUSERNAME is the username you want to switch too. ` wsl --unregister ubuntu wsl --import Ubuntu D:\wsl2distros C:\wslbackups%1%.tar ubuntu config --default-user YOURUSERNAME ` |
Step 1.) In your WSL/Linux Distribution enter command: id YOURUSERNAME (RECORD THE VALUE) Step 2.) Right click the start menu and select run, then type regedit and hit enter Step 3.) In the left panel navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\ Step 4.) In the left panel click on the drop down arrow next to the Lxss folder and select your Linux Distribution Step 5.) Locate the value titled "DefaultUid" and double click it Step 6.) In the box that appears enter the value you recorded in step 1 and select "Decimal" then hit enter MAKE SURE YOUR VALUE MATCHES THE RETURNED VALUE FROM STEP ONE AND MAKE SURE "DECIMAL" IS SELECTED If you've followed every step described above and you issue remains, throw your computer away and take up knitting |
Showwwwww. Omg |
@craigloewen-msft - that registry path does not exist in windows 11, I could create it, but it feel as the wrong solution if it did not come pre-existing with windows.
@cpbotha - that did not work, after wsl shutdown and start again I still came back as root OH I thought the ~/.wslconfig file! No! it was the /etc/wsl.conf file, that actually worked! |
Thanks for this, saved my life. |
This helped, thanks. |
@jglathe , I don't know about you, but this only happened to me when I changed the which drive WSL2 lived on. |
I actually changed the SSD in the box, so a UUID change might be possible deep down in the partition UUIDs. I restored a backup image, the IDs oft the GPT will at least have partially changed due to the restore method. Seen some other issues (power management related) though, did a recovery image restore, replaced the Windows partition with the backed-up one. Managed to repair the boot config with |
This ^^^ After exporting and importing to move WSL disk to a new location. |
Howdy to all , try this psmodule https://github.com/pnp/wsl2 or Import-Module PnP.Wsl2 , a way to manage wsl2 instances easy\peasy . There's the Import\Export cmdlet and the Copy that fix the resizing ... and actually solve the export lock problem bug ( im adding some updates this weekend) (#12434 (comment)) that is not solved still |
Your Windows build number: Microsoft Windows [Version 10.0.18932.1000]
What you're doing and what's happening:
> wsl.exe -d my-wsl2-distro
What's wrong / what should be happening instead:
It starts as root, even after
my-wsl2-distro.exe config --default-user my-user
.my-wsl2-distro.exe
starts as the default-user. It is quite problematic when using Remote-WSL on vscode, because it runs as the root user.The text was updated successfully, but these errors were encountered: