14

Windows 10's Anniversary Update just came out and I immediately installed the Windows Subsystem for Linux to see how it fares. I found only one major shortcoming so far: there was no obvious way to use the root account as the default.

I know it goes against a lot of best practices and what not, but I personally don't like having to remember to type sudo in front of most commands. This can get especially annoying when I open a text file for editing with nano only to discover I have to abandon my changes because I didn't use sudo.

Is there any way to make the terminal start as root by default?

16

The command to set the default Linux user is different in different versions of Windows.

For versions of WSL up to the Fall Creators Update, run the following command in an elevated Windows command prompt:

lxrun /setdefaultuser root

For installations after the Fall Creators Update, the command is:

<distro> config --default-user root

Substitute the distro's exe name for <distro> in the command above. So, if you're running Ubuntu, the command would be:

ubuntu config --default-user root

For openSUSE...

opensuse-42 config --default-user root

And, for SUSE Linux Enterprise Server, the command is...

sles-12 config --default-user root

Again, all of these commands are performed from an elevated Windows command prompt.

Note:
The examples above are for the root user. You may specify any other existing username in place of root.

4
  • 4
    For the newer Ubuntu 18.04 distro, the command is: ubuntu1804 config --default-user root
    – NetRay
    Aug 6 '18 at 15:37
  • Where can I see if I use the WSL fall creater update?
    – Timo
    Oct 23 '19 at 18:11
  • lxrun does not work in my powershell. I use Wsl Debian, do you know the command for this to start the app as root?
    – Timo
    Oct 23 '19 at 18:12
  • ubuntu2004 config --default-user root for Ubuntu 20.04 LTS Jan 10 at 11:20
18

In a command prompt with elevated permissions run the command lxrun /setdefaultuser root

lxrun is the tool for performing administrative operations on the LX subsystem.

2
  • 1
    Just to clarify: the lxrun command should be executed in a Windows command prompt. This solution works great. Jul 25 '17 at 14:09
  • 5
    The lxrun.exe command is no longer supported. Feb 2 '18 at 16:46
3

Use

ubuntu1604 config --default-user root & ubuntu1604.exe

I tried the solutions mentioned above but somehow I always end up with the user login rather than root

2
  • Thanks, this worked for me with these modifications: ubuntu config --default-user root & ubuntu.exe
    – appel
    Jul 3 '20 at 14:24
  • This worked for me, but being on Ubuntu 18.04 I needed to use `ubuntu1804 config --default-user <username> Aug 19 '20 at 21:15
3

Try my way if someone still needed.

My computer

  • Windows 10 winver: 21H1(19043).
  • Subsystem: Ubuntu 18.04 LTS.

Open Registry Editor with shortcut key: windows + r.

type: regedit and enter.

Go to this path: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss

and find the "DistributionName" you are using. (Ubuntu-18.04 is mine) Modify this name "DefaultUid" set value equal 0 then click Ok button to save. then log off and log in to reset Registry.

Open your bash shell and enjoy it.

0 is the root user's id, you can check by running this command cat /etc/passwd; and find root user.

1
  • worked for me :)
    – TechDog
    Jul 4 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.