Blog

How to enable Sudo on Windows 11

  • To enable sudo on Windows 11, open Settings > System > For developers, turn on “Enable sudo,” and choose the “Inline” option.
  • You can also open Command Prompt or PowerShell (admin) and run the “sudo config –enable normal” command.

On Windows 11, it’s now possible to enable “sudo,” and in this guide, I will outline the steps to complete this configuration. Starting on Windows 11 24H2, the system adds support for the sudo command for Command Prompt and PowerShell to run elevated commands without having to open the console as an administrator, similar to the command already available on Linux, macOS, and other Unix-based operating systems.

What is sudo?

Sudo (superuser do) is a command tool that allows users to execute commands with elevated privileges without running the console as an administrator. It essentially provides temporary elevation of privileges for a specific command.

This tool minimizes the time spent with elevated permissions, reducing the risk of accidental damage to the system. It also allows users to perform administrative tasks without logging in as root directly.

Unlike the version of sudo available on Linux, the one for Windows is very limited. If you want a more similar experience to the version on Linux, you have to use third-party tools, such as gsudo.

What are the sudo modes?

Sudo on Windows 11 offers three modes:

  • Inline: When running the sudo command, the console allows the execution of administrative tasks within the same window. You have to use this option if you want the same Linux experience.
  • With input disabled: This is the most secure experience. It runs the command in elevated mode in the current window, but the process will not have any more inputs. If you need to run additional processes, this mode will not work.
  • In a new window: When running the sudo command, the Terminal will open a new window as an administrator.

What operations are supported with sudo?

You can perform many operations using this command:

  • Deleting a protected file.
  • Invoking elevated commands.
  • Opening a new terminal to perform any task.

In this guide, I will teach you the steps to configure the sudo command on Windows 11. You can also bring the same Linux Sudo experience to version 23H2, 22H2, and Windows 10 with the gsudo tool.

Enable sudo on Windows 11 from Settings

To enable sudo on Windows 11 through the Settings app, use these steps:

  1. Open Settings on Windows 11.

  2. Click on System.

  3. Click the For developers page.

  4. Turn on the Enable sudo toggle switch.

  5. Click the “Enable sudo” setting.

  6. Choose the “Inline” mode from the “Configure how sudo runs applications” setting for a Linux-like experience.

    Configure how sudo runs apps

Once you complete the steps, you can start using the sudo command on the Windows Terminal whether you use Command Prompt or PowerShell.

Enable sudo on Windows 11 from Terminal

To turn on the sudo command through Command Prompt or PowerShell, use these steps:

  1. Open Start.

  2. Search for Windows Terminal, right-click the top result, and choose the Run as administrator option.

    Quick note: This would be the last time you will need to run the Terminal as admin. You can process the configuration in Command Prompt or PowerShell.

  3. Type the following command to enable sudo “Inline” mode on Windows 11 and press Enter:

    sudo config --enable normal

    Command Prompt enable sudo command

  4. (Optional) Type the following command to enable sudo “In a new window” mode and press Enter:

    sudo config --enable forceNewWindow
  5. (Optional) Type the following command to enable sudo “With input disabled” mode and press Enter:

    sudo config --enable disableInput

After you complete the steps, the sudo command will enable, and you can start using the command to run tools elevated without the need to start a console as an administrator.

Use sudo command on Windows 11

To run elevated commands with sudo on Windows 11, use these steps.

  1. Open Start.

  2. Search for Windows Terminal and click the top result to open the console.

  3. Type the following command to invoke the sudo command help and press Enter:

    sudo -h

    Sudo help command

    Quick note: This command will help you learn how to structure the command, the different arguments, and the available options.

  4. Type the following command to run a command with sudo on Windows 11 and press Enter:

    sudo del mytextfile.txt

    Using sudo command correctly

    Quick note: The command works by appending the sudo prefix before the actual command to elevate the process. The system would still show the “User Account Control” (UAC) dialog to confirm the elevation.

It’s important to note that the sudo command is case-sensitive but only for the available options. For example, sudo -h will bring up the help, but the sudo -H will produce an error.

Microsoft is adding this native support further to bridge the gap between Windows and Unix-like operating systems and make it easier for developers to work in the system with tools they already know.

If you already configured the Windows Terminal to start a command-line session as an administrator, you can still use the “Sudo” command, but it will make no difference since all the commands will already run elevated. 


Source link

Related Articles

Back to top button
close