sodcalculator

10 Tech How-To

Windows 11 sudo: Elevate One Command Easily

Guide 10-38573 · Updated · Step by step

To elevate a single command in Windows 11 without opening an admin console, prefix it with sudo in a normal (non-admin) terminal window. For example, type sudo net start spooler and press Enter; Windows will open a User Account Control (UAC) prompt, and after you confirm, the command runs with administrator rights.

What Is Sudo on Windows 11?

Sudo (superuser do) is a command-line utility that lets you run a command with elevated privileges. It has been a staple of Unix and Linux systems for decades. Windows 11 introduced a native sudo command starting with version 24H2 (the 2024 update). Before this, Windows users had to open an elevated Command Prompt or PowerShell window manually, or use third-party tools like gsudo. The native sudo aims to simplify that workflow: you stay in your current terminal, and only the specific command you prefix with sudo runs as administrator.

How to Enable Sudo in Windows 11

Sudo is not enabled by default in Windows 11. You must turn it on first, either through the Settings app or with a command.

  1. Open Settings (Win + I) and go to System > For developers.
  2. Find the Enable sudo toggle and switch it on.
  3. Choose how you want sudo to run: In a new window (default) or Inline. The inline option runs the command in the same terminal window, which is more similar to Linux behavior.

Alternatively, run this in an elevated PowerShell or Command Prompt:

sudo config --enable enable

After enabling, restart your terminal so the change takes effect. You can verify it works by typing sudo --version.

How to Use Sudo to Elevate a Single Command

Once enabled, using sudo is straightforward. Open any terminal—Command Prompt, PowerShell, or Windows Terminal—and prepend sudo to the command you want to elevate. Here are concrete examples:

  • sudo net start spooler – starts the Print Spooler service.
  • sudo ipconfig /release – releases your IP address (requires admin).
  • sudo sc query type= service – queries service information.
  • sudo del C:\Windows\Temp\somefile.log – deletes a file in a protected location.

When you run sudo, a UAC prompt appears. Click Yes to authorize. The command then executes with full administrator privileges, but only that one command. Your terminal session itself remains non-elevated, so subsequent commands run as a normal user unless you prefix them with sudo again.

Sudo vs. Run as Administrator: Key Differences

The traditional way to run an elevated command is to right-click the terminal icon and select Run as administrator. That opens a new, elevated window where every command runs with admin rights. Sudo offers a different model:

  • Granularity: Sudo elevates only the command you specify, not the whole session.
  • Security: With sudo, you reduce the risk of accidentally running an admin-level command that could harm your system, because the default session is non-elevated.
  • Workflow: Sudo lets you stay in your current directory and environment, whereas Run as administrator opens a new window that may reset your working directory.
  • UAC prompts: Both methods trigger a UAC prompt. Sudo cannot bypass UAC; it still asks for confirmation.

If you frequently need several admin commands in a row, opening an elevated terminal might be more efficient. But if you only need one occasional elevated command, sudo is cleaner and safer.

Common Problems and Troubleshooting

Several issues can arise when using sudo on Windows 11. Here are the most frequent ones and how to fix them:

  • “sudo is not recognized” error: This means sudo is not enabled or you are running an older Windows version. Go to Settings > System > For developers and enable it, or update Windows to 24H2 or later.
  • UAC prompt does not appear: If you are already running an elevated terminal (e.g., you opened it as administrator), sudo may not prompt again because the session is already elevated. That is expected behavior.
  • Sudo runs in a new window unexpectedly: The default mode is “new window.” If you want inline execution, change the setting in the For developers page or run sudo config --set mode inline.
  • Command fails with access denied: Even with sudo, some commands may require additional permissions or the command itself may not support elevation. Check the command’s syntax and ensure you typed it correctly.

Sudo Configuration Options

Windows 11 sudo supports a few configuration settings that control its behavior. You can view them with sudo config and change them with sudo config --set. The main options are:

  • enable – turns sudo on or off.
  • mode – sets the execution mode: inline (runs in the current window) or newWindow (opens a new elevated window).

For example, to set inline mode, run sudo config --set mode inline. Note that inline mode is still in preview and may have limitations. The new window mode is the default and is more stable.

Security Considerations

Using sudo is generally safer than running an entire terminal as administrator, but it is not without risks. Because sudo grants full admin rights to the specified command, a typo could have serious consequences. For instance, sudo del C:\Windows\* would attempt to delete system files. Always double-check the command and path before pressing Enter. Also, be aware that sudo does not protect you from malicious scripts: if you run a script with sudo, that script has full system access. Only use sudo on commands you trust.

Alternatives to Sudo

If sudo does not suit your needs, there are other ways to elevate a single command:

  • Run as administrator: Open a new elevated terminal and run the command there.
  • gsudo: A third-party tool that mimics Linux sudo and offers more features, like remembering elevation for a session.
  • PowerShell Start-Process: Use Start-Process -Verb RunAs to launch a program with admin rights, e.g., Start-Process notepad -Verb RunAs.
  • Task Scheduler: Create a task that runs with highest privileges and trigger it manually or via script.

Frequently Asked Questions

Does sudo work in PowerShell and Command Prompt?

Yes, sudo works in both PowerShell and Command Prompt (cmd), as well as in Windows Terminal. It is a system-level command, not tied to a specific shell.

Can I use sudo without enabling it in Settings?

No, sudo must be enabled first. You can enable it via Settings or with the sudo config --enable enable command, but the feature is off by default.

Why does sudo open a new window instead of running inline?

That is the default behavior. To run inline, change the mode to inline using sudo config --set mode inline or select it in Settings. Note that inline mode is still in preview and may have limitations.

Does sudo require an administrator account?

Yes, you need an administrator account to use sudo. Standard user accounts cannot elevate without entering an admin password, and Windows sudo does not support password input—it relies on UAC, which requires an admin account to approve.

Is sudo available on Windows 10?

No, sudo is exclusive to Windows 11 version 24H2 and later. Windows 10 users would need to use third-party tools like gsudo or the traditional Run as administrator method.

Can I use sudo in Windows Subsystem for Linux (WSL)?

Yes, inside a WSL distribution, the Linux sudo command works as it does on any Linux system. That is separate from the native Windows sudo command, which runs Windows commands.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →