The latest Windows 11 build introduces the sudo command to the operating system. Sudo plays an essential role on BSD, Linux, and other Unix-like systems as it allows users to run commands as another user. The most common application of sudo is to run programs as the superuser.
Microsoft describes its implementation of Sudo for Windows in a single sentence:
Sudo for Windows provides a new, yet familiar way to elevate processes directly from the command-line.
This is actually all you need to know about Microsoft’s implantation. In other words, you use sudo to elevate command line instructions.
A detailed article on the Windows Command Line Dev Blog provides additional information on Sudo for Windows.
Sudo for Windows: the details
Sudo for Windows is only available in the latest Windows 11 Insider Preview build 26052. Twitter user Bob Pony discovered that you may use Sudo for Windows on older versions of the operating system already as well. Support goes all the way down to Windows 7.
While not recommended, you may download the Sudo for Windows application from the linked post and add it to the System32 directory.
The feature is not enabled by default. You may enable it by running the command sudo config –enable normal from an elevated command prompt. Replace “normal” with one of the other options below, if you prefer those.
The application supports three states:
- In a new window (forceNewWindow) — runs the command in a new elevated window.
- With input disabled (disableInput) — runs the command without input option in the window it was triggered from.
- Inline (normal) — runs the command from the same window it was triggered from. Most similar to the sudo experience on *nix systems.
You find these options under System > For developers in the Windows Settings. Note that the options are not available if you copied the application manually to the System32 folder.
Tip: use the command sudo -h to display all available commands in the console.
Here is the output at the time of writing:
C:\Users\Martin\Downloads\sudo>sudo -h
Sudo for WindowsUsage: sudo [OPTIONS] [COMMANDLINE]… [COMMAND]
Commands:
run Run a command as admin
config Get current configuration information of sudo
help Print this message or the help of the given subcommand(s)Arguments:
[COMMANDLINE]… Command-line to runOptions:
-E, –copyEnv Pass the current environment variables to the command
–newWindow Use a new window for the command
–disableInput Run in the current terminal, with input to the target application disabled
-h, –help Print help (see more with ‘–help’)
-V, –version Print version
Using Sudo for Windows
Just prepend “sudo” in front of the command to run it elevated. The command sudo wsl.exe –install installs the Windows Subsystem for Linux. Windows would refuse to run it in an unelevated command prompt window.
With sudo, it displays an UAC prompt. Accept the prompt and the command is executed on the system. What happens next depends on the selected configuration.
- New window — Sudo for Windows launches a new elevated console window and executes the command in that window.
- Input closed and Inline — Sudo for Windows launches a new elevated sudo.exe process. The original sudo command establishes an RPC connection with that new process.
Closing Words
Sudo for Windows is open source. Microsoft published a new repository on GitHub that interested users may follow.