Advertisement

Switch User in WSL Linux Distro in Windows 10

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.

Advertisеment

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.

Linux Distros Microsoft Store Windows 10

After enabling WSL, you can install various Linux versions from the Store. You can use the following links:

  1. Ubuntu
  2. openSUSE Leap
  3. SUSE Linux Enterprise Server
  4. Kali Linux for WSL
  5. Debian GNU/Linux

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,

  1. Run your WSL Linux distro, e.g. Ubuntu.Windows 10 WSL Run As User 1
  2. Execute the command su - <username>. Alternative syntax is su -l <username> or su --login <username>.
  3. Substitute the <username> portion with the actual user name.
  4. Type the password for the user you are switching to when prompted.Windows 10 WSL Switch User
  5. To go back to your original user session, type exit.Windows 10 WSL Switch User Back

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.

The options -, -l, and --login tell the su binary to start  the shell as a login shell with an environment similar to a real login:
  • 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:

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:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.