Thursday, October 17, 2024

How to Use Sudo Command on Windows 11/Windows Server

Linux users have long enjoyed the convenience of "sudo," a simple command that grants temporary administrator privileges for a single command. Now, Windows 11 users can experience the same ease with the latest 2024 Update, which brings a built-in sudo functionality.

For years, Windows users had to navigate the cumbersome process of opening an elevated terminal window for every command requiring administrator permissions. While the runas command existed, it required manually specifying the user to run the command as, adding another layer of complexity.


The arrival of sudo in Windows 11 marks a significant step towards bridging the gap between the two operating systems, simplifying everyday tasks for both casual and power users.

Setting Up Sudo in Windows 11

Enabling sudo in Windows 11 is a straightforward process, achievable through either the Settings app or the command line:

Using the Settings App:

  1. Open the Settings app.

  2. Navigate to System and scroll down to find the For developers option.

  3. Toggle the Enable sudo switch to the On position.

For finer control over sudo's behavior, click the arrow next to the toggle. This will reveal three options for how sudo executes commands:

  • In a new window: This launches the command in a separate elevated window, allowing for subsequent commands if needed.

  • With input disabled: This opens a new window for the command but disables further user input.

  • Inline (recommended): This executes the command within the current window, displaying output directly.

Using the Command Line:

  1. Launch Windows Terminal or Command Prompt with administrator privileges.

  2. Execute the following command:

      sudo config --enable <configuration_option>
    

Replace <configuration_option> with one of the following arguments:

  • forceNewWindow: Run commands in a new window.

  • disableInput: Run commands with input disabled.

  • normal: Run commands inline (recommended).

Using Sudo in the Command Line

Once enabled, simply preface any command requiring elevation with "sudo" in a regular terminal window. For example, to view network connection information:

      sudo netstat -ab
    

While most commands function seamlessly with sudo, some discrepancies may arise. For instance, PowerShell commands like Get-AppXPackage might not work as expected, returning "command not found." This means operations related to installing or removing AppX packages, like the Game Bar, might not work. Additionally, commands executed in a new window may not display output as intended. Therefore, using the inline configuration is generally recommended for its simplicity and efficiency.

Enhanced Security and User Experience

Sudo's arrival in Windows 11 brings a welcome change to the user experience, streamlining the process of executing elevated commands. By eliminating the need for a perpetually elevated terminal session, sudo enhances security by requiring explicit user confirmation before executing commands with administrator privileges.

The long-awaited integration of sudo into Windows 11 signifies a significant step towards aligning the user experience with Linux, offering a familiar and efficient tool for managing system tasks. This move, coupled with the growing prevalence of hybrid environments, further reinforces the importance of interoperability between operating systems. As the feature evolves, we can expect even greater improvements and a more refined user experience.

0 comments:

Post a Comment