Software & AppsOperating SystemLinux

How To Change Default User in WSL Ubuntu Bash on Windows 10

Ubuntu 13

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.

Quick Answer

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.

Understanding WSL

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.

  1. Open the Windows Command Prompt: You can do this by searching for cmd in the Windows search bar and hitting enter.
  2. Run the ubuntu config Command: In the command prompt, type the following command:
    ubuntu config --default-user <new_username>
    Replace <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:
    ubuntu1804 config --default-user <new_username>
    for Ubuntu 18.04.

Method 2: Editing the /etc/wsl.conf File

This method involves editing the WSL configuration file to set the default user.

  1. Open the WSL Instance as Root: You can do this by running the following command in the Windows command prompt:
    wsl -u root
    This command opens the WSL instance with root user privileges.
  2. Create or Edit the /etc/wsl.conf File: 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:
    nano /etc/wsl.conf
    In the file, add the following lines:
    [user]
    default=<new_username>
    Replace <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.
  3. Save the File and Exit the Text Editor: If you’re using nano, you can do this by pressing Ctrl + X, then Y to confirm that you want to save the changes, and then Enter to confirm the file name.
  4. Terminate the WSL Instance: You can do this by running the following command in the Windows command prompt:
    wsl --terminate <distro_name>
    Replace <distro_name> with the name of your WSL distribution. This command terminates the running WSL instance.
  5. Restart the WSL Instance: The next time you start the WSL instance, it will use the new default username.

Conclusion

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.

Can I change the default user in WSL Ubuntu Bash to any username?

Yes, you can change the default user to any valid username that you want to set.

What happens if I don’t specify a username when using the `ubuntu config` command?

If you don’t specify a username, the default user will remain unchanged.

Can I change the default user for a specific version of Ubuntu in WSL?

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.

Do I need root privileges to edit the `/etc/wsl.conf` file?

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.

Can I use any text editor to create or edit the `/etc/wsl.conf` file?

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.

Will changing the default user affect my existing files and configurations in WSL?

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.

Do I need to restart the WSL instance after making changes to the default user?

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.

Leave a Comment

Your email address will not be published. Required fields are marked *