The Windows Subsystem for Linux (WSL) is a powerful tool that allows users to run a Linux environment directly on Windows, without the need for a dual-boot setup or a virtual machine. One of the features of WSL is the ability to change the default user that signs in when starting a new session. This article will guide you through the process of changing the default user on WSL.
To change the default user on WSL, you can either use the
wsl.conf file or reset the instance. Using the
wsl.conf file allows you to specify a default user by editing the configuration file. Resetting the instance will take you back to the initial configuration stage, where you can set a new default user.
- Understanding WSL
- Option 1: Using wsl.conf
- Option 2: Reset the Instance
Before we dive into the steps, it’s important to understand what WSL is. WSL is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. It allows developers to use a GNU/Linux environment â€” including most command-line tools, utilities, and applications â€” directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.
Option 1: Using
The first method to change the default user on WSL is by using the
wsl.conf file. This is a configuration file that WSL reads every time it starts up.
Step 1: Create
Open your WSL instance and create a
/etc/wsl.conf file. You can do this by typing the following command in your WSL terminal:
sudo nano /etc/wsl.conf
This command uses
sudo to run the command as an administrator,
nano to open the nano text editor, and
/etc/wsl.conf is the path to the configuration file.
Step 2: Add Configuration
wsl.conf file, add the following lines:
<username> with the username of the user you want to set as the default. This block of code tells WSL to set the default user to the specified username.
Step 3: Save and Exit
wsl.conf file by pressing
Y to confirm the save, and finally
Enter to exit nano.
Step 4: Terminate WSL Instance
Exit your WSL instance and terminate it by running the following command in PowerShell or CMD:
wsl --terminate <distribution>
<distribution> with the name of your WSL distribution (e.g., “Ubuntu”). This command tells WSL to terminate the current instance.
Step 5: Restart WSL Instance
Restart your WSL instance, and it should now sign in with the specified default user.
Option 2: Reset the Instance
The second method to change the default user on WSL is to “reset” the instance back to the configuration stage. This method is more destructive and will reset your WSL instance to its initial state. Make sure to back up any important data before proceeding.
Step 1: Export a Backup
Open a PowerShell or CMD prompt and export a backup of your current WSL instance by running the command:
wsl --export <distribution> "<backup_filename>.tar"
<distribution> with the name of your WSL distribution and
<backup_filename> with a name for your backup file. This command exports a backup of your current WSL instance.
Step 2: Unregister the WSL Instance
Once you have a backup, unregister the current WSL instance by running:
wsl --unregister <distribution>
<distribution> with the name of your WSL distribution. This command unregisters the current WSL instance.
Step 3: Re-Run the Configuration Step
Run the WSL app again, either by running
ubuntu.exe or the version-specific app from the Microsoft Store. The configuration step will re-run, asking for the default username and password. Follow the prompts to set the desired default user.
Changing the default user on WSL can be done in a few steps, either by using the
wsl.conf file or by resetting the instance. Both methods have their own advantages and disadvantages, so choose the one that best fits your needs. Always remember to backup your data before making any major changes to your system.
No, the user you want to set as the default must already exist in your WSL instance.
Yes, you can also change the default user by resetting the WSL instance back to the configuration stage. However, this method is more destructive and will reset your WSL instance to its initial state.
No, changing the default user will not affect your existing files and configurations. It only changes the user that signs in by default when starting a new session.
Yes, you can change the default user on WSL multiple times by following the steps mentioned in the article.
Yes, you need administrative privileges to create and modify the
wsl.conf file in the