The 'default user' argument is not a runtime flag for wsl --update but a configuration setting stored in the distro's metadata. When updates occur, WSL preserves this setting from the previous version. If it appears ignored, the issue usually stems from cached state or a mismatch between the installed version and the registered default user, requiring verification of the current configuration rather than passing incorrect arguments.
Understanding How Default User Works
In Windows Subsystem for Linux (WSL), the default user is determined at the time of installation or when explicitly changed by an administrator. This setting is persisted in the virtual hard disk (.vhdx) file associated with each distribution. It is not passed as a command-line argument during routine operations like updating the kernel or the package manager.
The command wsl --set-default-user <Distro> <User> is the correct way to change this behavior. For example, running wsl --set-default-user Ubuntu myuser ensures that subsequent launches of the Ubuntu distro start as myuser. The update process itself does not accept a --user flag because it is designed to upgrade the underlying system files without altering the user configuration unless explicitly instructed to do so via the set-default command.
Why Updates Seem to Ignore Settings
When you run wsl --update, WSL downloads and installs the latest Linux kernel components and base utilities. During this process, the existing instance of your distribution is stopped, updated, and then restarted. The expectation that the default user would be reset or re-evaluated during this cycle is incorrect. The system retains the last known good default user from the previous session.
If you observe that the default user has reverted to root or another unexpected account after an update, it is likely because the update process detected a corruption in the user mapping or the instance was previously configured to start as root. In some cases, if the original user account was deleted or renamed on the Windows host, WSL may fall back to a safe default, which is often root, to prevent the distribution from failing to launch.
Verifying and Resetting the Default User
To resolve issues where the default user seems incorrect, you should first verify the current status. You can check which user is currently set as default by looking at the instance details. However, the most reliable method is to explicitly set the default user again after ensuring the distro is properly installed.
- Open PowerShell or Command Prompt as Administrator.
- List all installed distributions to confirm the name:
wsl -l -v. - Set the default user using the syntax:
wsl --set-default-user <DistributionName> <Username>. - Launch the distribution to test:
wsl -d <DistributionName>.
This sequence ensures that the metadata is correctly written to the distro's configuration store. If the username you specify does not exist within the Linux environment, WSL will fail to launch or will drop you into a root shell depending on the version. Always ensure the user exists inside the distro before setting them as default.
Troubleshooting Permission Issues After Update
Sometimes, the perceived "ignoring" of the default user is actually a permission error. If the update process modifies file ownerships or if the home directory permissions become corrupted, the new user may not be able to access their files. This can cause the shell to appear broken or behave unexpectedly, leading users to believe the user context is wrong.
To fix this, you may need to enter the distro as root temporarily. You can do this by specifying the user directly in the launch command: wsl -u root -d <DistributionName>. Once inside, you can check the ownership of your home directory using ls -la ~. If the files are owned by root, you can change the ownership back to your user with sudo chown -R $USER:$USER ~.
Another common issue arises when the Windows host user profile path changes. If you moved your WSL installation to a different drive or changed your Windows username, the symlink to the home directory might break. In such cases, verifying the /etc/passwd file inside the distro can help identify if the home directory path is still valid.
Using Sudo Correctly
The suggestion to use sudo is relevant only if you are already logged in as a user who needs elevated privileges to perform administrative tasks. It is not a fix for the default user configuration itself. If you are stuck in a root shell due to a failed default user setup, you can create a new user and grant them sudo privileges. Use adduser <newusername> to create the user, then add them to the sudo group with usermod -aG sudo <newusername>.
After creating the new user, you can set them as the default using the --set-default-user command mentioned earlier. This approach bypasses any corruption in the original user's configuration while maintaining system security.
Preventing Future Conflicts
To avoid confusion between the Windows host user and the WSL guest user, it is helpful to understand that they are separate entities. A Windows user named "John" does not automatically have a corresponding "John" in Ubuntu unless explicitly created. Best practice is to install WSL, create a non-root user immediately, and set that user as the default. This prevents the common pitfall of starting as root, which can lead to permission issues later.
If you encounter persistent issues, consider exporting the distro, removing it, and reinstalling it fresh. This ensures a clean slate for user configurations. Before doing this, back up your data using wsl --export to preserve your files and settings.
Frequently Asked Questions
Can I pass a user argument to wsl --update?
No, the wsl --update command does not support user-specific arguments. It only updates the WSL kernel and base components. To change the default user, you must use the wsl --set-default-user command separately.
Why did my default user revert to root after an update?
This typically happens if the original user account was deleted or if there was a conflict in the user mapping during the update. Verifying the existence of the user inside the distro and re-setting the default user usually resolves this.
How do I check which user is currently the default?
There is no direct command to query the default user setting. However, launching the distro without specifying a user will show you who you log in as. You can also inspect the instance configuration in the Windows Registry or by checking the distro's internal /etc/passwd file if accessible.
Is it safe to use sudo for all updates?
Using sudo for package updates inside the distro is standard practice, but it does not affect the WSL default user setting. The default user is a WSL-level configuration, independent of the package manager permissions within the Linux environment.
What if I cannot access my distro because the default user is wrong?
You can force launch the distro as root by using the command wsl -u root -d <DistroName>. From there, you can diagnose permission issues, recreate users, or reset the default user configuration.