Use sudo in Windows 11 Like a Pro: Unlock Admin Power

blog-post-feature-image-enabling-saudo-into-windows-11

Do you want to run commands with elevated privileges on Windows 11 without switching to the administrator account? Do you want to have the same convenience and flexibility as Linux and Mac OS users when using the sudo command? If yes, then you are in luck. Windows 11 now supports the sudo command as a native feature, and you can enable it with just a few simple steps.

In this blog post, I will show you how to enable sudo for Windows 11 and how to use it with different modes and options. By the end of this tutorial, you will be able to run any command that requires administrator permissions with the sudo command on Windows 11. Let’s get started. 

✅

Open Settings ⚙️ and navigate to System > Developers then Toggle Enable sudo to On. Choose inline mode ➡️ for a familiar experience.

Prerequisites

To enable and use the sudo command on Windows 11, you need to have the following:

  • A Windows 11 device with build 26052 or higher, or version 24H2, which is expected to be released during the second half of 2024.
  • An administrator account on your device, or the credentials of an administrator account that you can use to confirm the elevation of the commands.
  • The Windows Terminal app, which you can download from the Microsoft Store or this link.

How to Enable the Sudo Command on Windows 11

There are two methods to enable the sudo command on Windows 11: through the Settings app or through the Windows Terminal app. I will explain both methods in this section.

Method 1: Through the Settings App

The first method to enable the sudo command on Windows 11 is through the Settings app. Here are the steps to follow:

#1. Open the Start menu and look for Settings. Click on it to open the Settings app.

open-the-start-menu-and-look-for-settings

#2. In the Settings app, go to System and open the For developers page.

in-the-settings-app-go-to-system-and-open-the-for-developers

#3. On the For developers page, scroll down and turn on the Enable sudo setting.

on-the-for-developers-page-scroll-down-and-turn-on-the-enable

#4 Now, choose the mode that you want to use with the sudo command. There are three modes available: InlineIn a new window, and Input disabled. I will explain the differences between these modes later in this post. For now, the recommended mode is to use the Inline option, which will give you the same experience as using the sudo command on Linux and Mac OS.

click on the inline option

That’s it. You have successfully enabled the sudo command on Windows 11 using the Settings app

Method 2: Through the Windows Terminal App

The second method to enable the sudo command on Windows 11 is through the Windows Terminal app. Here are the steps to follow:

#1 Open the Start menu and look for the Terminal app. Right-click on it and select the Run as administrator option. This will open the Windows Terminal app as an administrator. This is going to be the last time that you have to right-click the console and run it as an administrator.

open the start menu and click on the terminal app

#2 In the Windows Terminal app, you can use either the Command Prompt or the PowerShell. To enable the sudo command, you need to run the following command:

sudo config --enable <mode>

Replace <mode> with the mode that you want to use with the sudo command. There are three modes available: normalforce-new-window, and disable-input. These modes correspond to the InlineIn a new window, and Input disabled options in the Settings app, respectively. For example, to enable the inline mode, you need to run this command:

sudo config enable normal
enable-the-inline-mode-you-need-to-run-this-command

The command will output the sudo mode that is set. For example, it will say:

The sudo mode is set to inline mode.
command-will-output-the-sudo-mode

You can switch between the three modes by typing the command with the different mode options.

That’s it. You have successfully enabled the sudo command on Windows 11 using the Windows Terminal app.

How to Use the Sudo Command on Windows 11

Now that you have enabled the sudo command on Windows 11, you can use it to run commands that require administrator permissions. Here are some tips and examples on how to use the sudo command on Windows 11.

  • To see the options and arguments available with the sudo command, you can type sudo -h and press Enter. This will show you the help information for the sudo command.
see-the-options-and-arguments-available-with-the-sudo-command

Just remember that when using the actual sudo command, you need to use a tool that is case-sensitive. For example, sudo -H will generate an error, but sudo -h will work.

you-need-to-use-the-tool-that-is-case-sensitive

  • To run a Windows command with the sudo command, you just need to type sudo followed by the command that you want to run. For example, if you want to delete a file that is in the root of the C drive, you can type sudo del C:\file1.txt and press Enter.
f-you-want-to-delete-a-file-that-is-in-the-root-of-the-c-drive

The sudo command will elevate the command and execute it with administrator permissions. You may or may not see the User Account Control dialog box to confirm the elevation, depending on your account type and settings.

the-sudo-command-will-elevate-the-command-and-execute-it

  • To run a PowerShell command with the sudo command, you need to type sudo powershell followed by the command that you want to run. For example, if you want to create a new registry key, you can type sudo powershell New-Item -Path HKLM:\Software\MyKey and press Enter. The sudo command will elevate the PowerShell command and execute it with administrator permissions.

The sudo command works with different modes, which affect how the command is executed and how the console behaves. Here are the differences between the three modes:

  1. Inline mode: This is the default and recommended mode. It runs the command with elevated privileges within the same window. This means that you can run multiple commands with the sudo command in the same window, and you can see the output of the commands in the same window. This mode gives you the same experience as using the sudo command on Linux and Mac OS.
  2. In a new window mode: This mode runs the command with elevated privileges in a new window. This means that when you use the sudo command, the terminal will open a new window as an administrator to run the command and any additional commands. This mode may be useful if you want to separate the elevated commands from the regular commands, or if you want to run a command that requires a new window, such as sudo shutdown /r.
  3. Input disabled mode: This is the most secure mode. It runs the command with elevated privileges inside the current window, but the process won’t allow you to execute any more inputs. This means that you can only run one command with the sudo command in the current window, and you cannot see the output of the command in the current window. This mode may be useful if you want to run a command that does not require any input or output, such as sudo sfc /scannow.

Wrapping Up

So, there you have it! With sudo now a resident of your Windows 11 toolbox, you can tackle those administrative tasks with the same ease as your Linux and Mac. Remember, with great power comes great responsibility, so use sudo judiciously and choose the mode that best suits your comfort level and security needs.


Imran Khan

Imran Khan

Hi, I’m Imran Khan, founder of Tech Adeptly. I love exploring new technologies and sharing my insights with others who are passionate about tech. That’s why I created this blog, where you can find helpful articles on various topics related to technology.

Leave a Reply

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