How to Log In as Root on Ubuntu WSL
You log in as the root user on Ubuntu WSL by using the ‘wsl -d ‘ command with the ‘-u root’ flag.
Logging in as root grants you full superuser privileges within your Ubuntu subsystem, letting you perform system-level administrative tasks. This access is crucial for tasks like installing sensitive packages or modifying critical system files.
You might need this elevated access when performing complex system configurations or troubleshooting deep-seated issues. For example, directly editing files in the /etc directory often requires root permissions.
Close your Ubuntu WSL session and open Command Prompt. Run `ubuntu config –default-user root` (or `ubuntu2004` / `ubuntu1804` for specific versions) to set root as the default user. Relaunch Ubuntu WSL to log in as root.
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?
Logging in as root on Ubuntu WSL gives you full control, like being the system’s administrator, but it’s risky business.
You might need to install or configure software that requires root access. In those cases, logging in as root can be necessary. Remember to log back in as a regular user after completing your task.
How to Log In as Root on Ubuntu WSL
Step 1Close Your Current Ubuntu Session
First, close the Ubuntu console if it’s currently open.
Step 2Open Windows Command Prompt
Click the Start button and search for “Command Prompt.” Open it when you find it.
Step 3Run the Configuration Command
In the Command Prompt, type the command below that matches your Ubuntu version. This command sets 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

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

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 5Switch Back to Your Regular User Account
After you’ve finished your admin tasks, it’s important to switch back to your regular user account in WSL.
⚠️ ADMIN REQUIRED
ubuntu2004 config --default-user username
Replace username with your actual account name, for example:
ubuntu2004 config --default-user user1

Now when you launch Ubuntu WSL, you’ll be back to your regular user account.
Summary
To log in as root on Ubuntu WSL, remember it’s for important tasks only, and always switch back to your normal user account afterward.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
Why not just use the normal method with the “su” command. Works just fine for me and is a lot easier and faster.
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
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.
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.
you saved my life man, I lost sudoers access using an user. !! it worked
Thank you. This worked.
Hi – is there a way to do this on Windows 11? ubuntu and ubuntu2004 does not work in command prompt.
Thanks
[…] How to login as root on WSL with Linux OS […]