How to Log In as Root on Ubuntu WSL

This tutorial will show you how to log in as root when using Ubuntu on Windows WSL. If you’re new to Linux, this guide makes it simple and easy to follow.

What is Windows Subsystem for Linux (WSL)?

Windows Subsystem for Linux (WSL) is a tool that lets you run a Linux environment directly in Windows. You get access to command-line tools, utilities, and applications without setting up a virtual machine or dual-boot. We have written many tutorials on installing different Linux distributions on Windows WSL.

Why Log In as Root?

Root is the administrator account on Linux. Logging in as root gives you special powers to make critical system changes. However, you should only do this when necessary. Why? Because mistakes made as root can damage your system. That’s why it’s safer to use a regular user account for everyday tasks.

There might be times when you need to install or configure software that requires root access. In those cases, logging in as root can be necessary. Just remember to log back in as a regular user after completing your task.

How to Log In as Root on Ubuntu WSL

Step 1: Close Your Current Ubuntu Session

First, close the Ubuntu console if it’s currently open.

Step 2: Open Windows Command Prompt

Click the Start button and search for “Command Prompt.” Open it when you find it.

Windows Command Prompt window ready for WSL commands

Step 3: Run the Configuration Command

In the Command Prompt, type the command below that matches your Ubuntu version. This command tells Ubuntu to log in as root by default.

⚠️ ADMIN REQUIRED

ubuntu config --default-user root

Or for Ubuntu 20.04:

ubuntu2004 config --default-user root

Or for Ubuntu 18.04:

ubuntu1804 config --default-user root

Ubuntu WSL terminal starting with root user access

Step 4: Launch Ubuntu WSL

Open the Ubuntu WSL app. This time you will be logged in as root instead of a regular user.

Ubuntu WSL console displaying root login prompt

What Happens When You’re Logged In as Root?

You now have full access to make system changes. The prompt will show a # symbol instead of a $ symbol. This tells you that you’re logged in as root. Perform whatever tasks you need to do while logged in as root.

Step 5: Switch Back to Your Regular User Account

When you’re done with your root tasks, switch back to your regular user account. Open Windows Command Prompt again and type:

⚠️ ADMIN REQUIRED

ubuntu2004 config --default-user username

Replace username with your actual account name, for example:

ubuntu2004 config --default-user user1

Ubuntu WSL console showing normal user login session

Now when you launch Ubuntu WSL, you’ll be back to your regular user account.

Summary

Logging in as root on Ubuntu WSL should only be done when you need to perform critical system tasks. Use the config --default-user command to switch between root and your regular user account. Always remember to switch back to your regular user account when you’re done with your tasks. This keeps your system safer and more secure. Familiarize yourself with these commands so you can switch users quickly whenever needed.

Frequently Asked Questions

How do I log in as root on Ubuntu WSL?

To log in as root on Ubuntu WSL, open the Windows Command Prompt and type the command 'ubuntu config –default-user root' for Ubuntu. After running this command, start the Ubuntu WSL app, and you should be logged in as the root user.

Is it safe to use the root account on Ubuntu WSL?

Using the root account can be risky as it gives you full control over the system, which may lead to accidental damage. It is recommended to use the root account only for specific tasks that require elevated privileges and to switch back to a regular user account afterward.

What should I do after finishing tasks as root on Ubuntu WSL?

After completing your tasks as the root user, it is important to log back into your standard user account. You can do this by running the command 'ubuntu config –default-user your_username' in the Windows Command Prompt, replacing 'your_username' with your actual username.

Can I change the default user back to a regular account in Ubuntu WSL?

Yes, you can change the default user back to a regular account by using the command 'ubuntu config –default-user your_username' in the Windows Command Prompt. Make sure to replace 'your_username' with the name of your standard user account.

Why would I need to log in as root on Ubuntu WSL?

You may need to log in as root on Ubuntu WSL to perform critical system tasks that require administrative privileges, such as installing software or configuring system settings. However, this should be done cautiously and only when necessary.

Categories:

,
  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

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