Each WSL Linux distro you have installed in Windows 10 contains its own set of user accounts. A WSL distro starts with its default user account that will be signed in automatically. It is possible to override the default user account and start a distro with a specific user account signed in by default. Also, you can switch between Linux user accounts without leaving your WSL session.
The ability to run Linux natively in Windows 10 is provided by the WSL feature. WSL stands for Windows Subsystem for Linux, which initially, was limited to Ubuntu only. Modern versions of WSL allow installing and running multiple Linux distros from Microsoft Store.
After enabling WSL, you can install various Linux versions from the Store. You can use the following links:
and more.
At the first run, a WSL distro offers you to create a new user account. It will be used as your default user account in this distro. Also, it will be added to the sudoers list, a group of users that are allowed to run commands as root (i.e. elevated) by executing the sudo command, e.g. sudo vim /etc/default/keyboard
. You can add more users to your WSL distro as described in the post Add User to WSL Linux Distro in Windows 10.
If you have more than one user account in a WSL distro, you can switch between them with the su
command.
To Switch User in WSL Linux Distro in Windows 10,
- Run your WSL Linux distro, e.g. Ubuntu.
- Execute the command
su - <username>
. Alternative syntax issu -l <username>
orsu --login <username>
. - Substitute the
<username>
portion with the actual user name. - Type the password for the user you are switching to when prompted.
- To go back to your original user session, type exit.
Note: If you have the root account enabled in your WSL distro, omitting the <username>
portion in the su command will sign in you with the root account. The command will look as follows: su -
. Note that in Ubuntu the root account is disabled by default.
- It clears all the environment variables except TERM and variables specified by --whitelist-environment.
- It initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH.
- It changes to the target user's home directory.
- It sets argv[0] of the shell to '-' in order to make the shell a login shell.
That's it.
Related articles:
- Add User to WSL Linux Distro in Windows 10.
- Update and Upgrade WSL Linux Distro in Windows 10
- Run WSL Linux Distro as Specific User in Windows 10
- Reset and Unregister WSL Linux Distro in Windows 10
- Reset Password for WSL Linux Distro in Windows 10
- All Ways to Run WSL Linux Distro in Windows 10
- Set Default WSL Linux Distro in Windows 10
- Find Running WSL Linux Distros in Windows 10
- Terminate Running WSL Linux Distro in Windows 10
- Remove Linux from Navigation Pane in Windows 10
- Export and Import WSL Linux Distro in Windows 10
- Access WSL Linux Files from Windows 10
- Enable WSL in Windows 10
- Set Default User for WSL in Windows 10
- Windows 10 Build 18836 Shows WSL/Linux File System in File Explorer
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options: