Enabling Root as Default User in WSL on Windows 10

If you want to set the default user in Windows Subsystem for Linux (WSL) to “root” instead of your regular user, you can achieve this using PowerShell or by modifying the WSL configuration file. Please note that running WSL as the root user is generally not recommended for security reasons, as it can expose your system to potential risks. Proceed with caution and only if you have a valid reason for doing so.

Here’s how you can enable the root user as the default user in WSL using PowerShell and by modifying the configuration file:

Using PowerShell:

  1. Open PowerShell: Press Win + X and select “Windows PowerShell” or “Windows PowerShell (Admin)”.

  2. Set Root as Default User: Run the following command to set the default user to root for a specific WSL distribution (replace “ubuntu2004” with the actual name of your distribution):

    1
    
    wsl --set-default-user root
  3. Start WSL: Launch your desired WSL distribution. It should now start with the root user as default.

Using WSL Configuration File:

  1. Locate Configuration File: The WSL configuration file can be found at C:\Users\<YourUsername>\AppData\Local\Packages\<DistroPackageName>\LocalState\rootfs\etc\wsl.conf.

    Replace <YourUsername> with your Windows username and <DistroPackageName> with the package name of your WSL distribution (e.g., for Ubuntu 20.04, the package name might include “CanonicalGroupLimited.Ubuntu20.04onWindows”).

  2. Edit Configuration File: Open the wsl.conf file in a text editor (e.g., Notepad).

  3. Add Default User Setting: Add the following lines to the wsl.conf file to set the default user as root for that distribution:

    1
    2
    
    [user]
    default=root
  4. Save the File: Save the changes and close the text editor.

  5. Restart WSL: Restart your computer or execute the following command in PowerShell to terminate all running WSL instances:

    1
    
    wsl --shutdown

After completing these steps, your chosen WSL distribution should start with the root user as the default user.

Remember that running WSL as the root user might lead to unintended consequences, and it’s important to exercise caution and be aware of the potential security risks involved.

0%