In this article, we will delve into the process of changing the default user in Windows Subsystem for Linux (WSL) Ubuntu Bash on Windows 10. This can be useful in scenarios where you want to run the WSL with a different user than the one set during the initial setup.
To change the default user in WSL Ubuntu Bash on Windows 10, you can use the
ubuntu config command or edit the
/etc/wsl.conf file. Both methods allow you to set a new default username for your WSL instance.
WSL, or Windows Subsystem for Linux, is a compatibility layer for running Linux binary executables natively on Windows 10. 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.
Changing the Default User in WSL Ubuntu Bash
There are several ways to change the default user in WSL Ubuntu Bash on Windows 10. We will be looking at two of the most common methods.
Method 1: Using the
ubuntu config Command
This method is straightforward and involves using the
ubuntu config command in the Windows command prompt.
- Open the Windows Command Prompt: You can do this by searching for
cmdin the Windows search bar and hitting enter.
- Run the
ubuntu configCommand: In the command prompt, type the following command:
ubuntu config --default-user <new_username>
<new_username>with the username that you want to set as the default. This command sets the default user for the Ubuntu instance to the specified username. If you have multiple Ubuntu versions installed, use the appropriate command for the specific version, such as:
for Ubuntu 18.04.
ubuntu1804 config --default-user <new_username>
Method 2: Editing the
This method involves editing the WSL configuration file to set the default user.
- Open the WSL Instance as Root: You can do this by running the following command in the Windows command prompt:
This command opens the WSL instance with root user privileges.
wsl -u root
- Create or Edit the
/etc/wsl.confFile: You can use a text editor like nano or vim to create or edit this file. For example, you can use the nano text editor by typing:
In the file, add the following lines:
<new_username>with the username that you want to set as the default. This sets the default user for the WSL instance to the specified username.
- Save the File and Exit the Text Editor: If you’re using nano, you can do this by pressing
Ctrl + X, then
Yto confirm that you want to save the changes, and then
Enterto confirm the file name.
- Terminate the WSL Instance: You can do this by running the following command in the Windows command prompt:
wsl --terminate <distro_name>
<distro_name>with the name of your WSL distribution. This command terminates the running WSL instance.
- Restart the WSL Instance: The next time you start the WSL instance, it will use the new default username.
Changing the default user in WSL Ubuntu Bash on Windows 10 can be accomplished through the
ubuntu config command or by editing the
/etc/wsl.conf file. Both methods are effective and can be used based on your preference. Remember to replace
<new_username> with the actual username that you want to set as the default.
Yes, you can change the default user to any valid username that you want to set.
If you don’t specify a username, the default user will remain unchanged.
Yes, you can specify the version of Ubuntu by using the appropriate command, such as
ubuntu1804 config --default-user <new_username> for Ubuntu 18.04.
Yes, you need root privileges to create or edit the
/etc/wsl.conf file. You can open the WSL instance as root by running
wsl -u root in the Windows command prompt.
Yes, you can use any text editor of your choice, such as nano or vim, to create or edit the
/etc/wsl.conf file. Just make sure you have the necessary permissions.
Changing the default user will not affect your existing files and configurations in WSL. It only changes the default user used when starting a new WSL instance.
Yes, you need to terminate the running WSL instance using the
wsl --terminate <distro_name> command and then start a new instance for the changes to take effect.