How to login as root on Ubuntu with Windows WSL

|

,

|

This text presents a tutorial on logging in as a root user in Ubuntu on a Windows WSL environment. After installing Ubuntu on Windows Subsystem for Linux (WSL), users can execute specific commands depending on the Ubuntu version to log in as root. Nevertheless, the author advises against usual root user login but admits there…

This brief tutorial will show students and new users how to log in as root when using Ubuntu on a Windows WSL environment.

Windows Subsystem for Linux (WSL) is a tool that lets developers run a GNU/Linux environment, including most command-line tools, utilities, and applications, directly in Windows without setting up a virtual machine or dual-boot.

You can run full Linux operating systems inside Windows efficiently. We have written many tutorials on installing different Linux distributions on Windows WSL.

Logging in as root on Ubuntu with Windows WSL should only be done in certain situations where you need to perform critical system tasks that require root privileges. It’s generally not recommended to use the root account for normal day-to-day use, as it can be risky and can potentially damage your system.

However, there might be instances where you need to install or configure software that requires root access. In those cases, logging in as root can be necessary. Just make sure to log back in as a regular user after completing the task to minimize the risk of accidentally causing any damage to the system.

I don’t think you should log in as root on a Linux machine. But there might be some cases where you’ll need to log in as root to perform critical tasks.

The tutorial should come in handy when you log on as root.

Log on as root

As you can see, launching the Ubuntu WSL app logs directly into the standard user account. See the below screenshot.

The first user, after installing, is the default account.

Use the steps below to start the Ubuntu WSL app and log in as root instead.

First, close the Ubuntu console prompt for the average user.

Then open the Windows command prompt by clicking the start button and find the Command Prompt or search for it, as shown in the image below.

When the command Prompt opens, type the commands below to configure the Ubuntu WSL app to log in as root instead of a regular user account.

Ubuntu:

ubuntu config --default-user root

Ubuntu 20.04:

ubuntu2004 config --default-user root

Ubuntu 18.04:

ubuntu1804 config --default-user root

After running the command above for the respective Ubuntu version, start up the Ubuntu WSL app, and this time the root account should be logged in.

You can see that the root account is logged in.

Now, do what you intend to do with the root account. When you’re done, exit.

You need to log back in with the standard account. Simply relaunch Windows Comment Prompt and run the commands below, replacing the root user with the standard account.

ubuntu2004 config --default-user richard

Replace richard with your account.

There you go.

That should do it!

Conclusion:

This post showed you how to log on as root when using Ubuntu on WSL. If you find any error above, please use the comment form below to report.

Like this:



8 responses to “How to login as root on Ubuntu with Windows WSL”

  1. jack Avatar
    jack

    Why not just use the normal method with the “su” command. Works just fine for me and is a lot easier and faster.

    1. redhatprincess Avatar
      redhatprincess

      Because that doesn’t work for everyone. I literally tried to do that on a VM that I didn’t personally create and it didn’t work and I was locked out. His instructions helped me be able to access root

  2. Brian Avatar
    Brian

    Thanks! I just needed to set up my user in sudoers and now I won’t have to do this anymore. But that first time I had no idea what to do.

  3. Panashe Avatar
    Panashe

    Yeah it does work on nearly everything but for “wget -q0” commands, it won’t work. Those commands will require one to run it as the actual root for the host system.

  4. ricard Avatar
    ricard

    you saved my life man, I lost sudoers access using an user. !! it worked

  5. iyad Avatar
    iyad

    Thank you. This worked.

  6. mck Avatar
    mck

    Hi – is there a way to do this on Windows 11? ubuntu and ubuntu2004 does not work in command prompt.

  7. platon Avatar
    platon

    Thanks

Leave a Reply to Panashe Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.