---
title: "How to Integrate the Linux Sudo Windows Port and PowerShell"
description: "Escalate your applications with administrative privileges through the Sudo Windows port or with gsudo and take control of your system!"
canonical: "https://adamtheautomator.com/sudo-windows-port/"
---

# How to Integrate the Linux Sudo Windows Port and PowerShell

> Escalate your applications with administrative privileges through the Sudo Windows port or with gsudo and take control of your system!

Source: https://adamtheautomator.com/sudo-windows-port/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Integrate the Linux Sudo Windows Port and PowerShell](https://adamtheautomator.com/wp-content/uploads/2023/06/sudo-windows-port.jpg)

# How to Integrate the Linux Sudo Windows Port and PowerShell

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)14 June 20234 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing the Linux Sudo Windows Port](#installing-the-linux-sudo-windows-port)
*   [Elevating Privileges with Sudo in PowerShell](#elevating-privileges-with-sudo-in-powershell)
*   [Installing and Using gsudo as an Alternative to sudo](#installing-and-using-gsudo-as-an-alternative-to-sudo)
*   [Conclusion](#conclusion)

Are you a systems and network administrator working with Windows-centric clients, servers, and networked services? If so, chances are you have already seen the popular Linux command line tool called Sudo. But how does the Linux Sudo Windows port work in PowerShell?

In this tutorial, you will learn how to install the Linux Sudo Windows port in PowerShell. Get yourself a powerful resource combining advantages for your daily operations.

Ready? Dive in to get the best of both worlds!

## Prerequisites

This tutorial comprises hands-on demonstrations. Ensure you have the following in place to follow along:

*   A Windows system with PowerShell installed – This tutorial uses Windows 10 with PowerShell 7 installed.

Related:[PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

*   [Scoop](https://adamtheautomator.com/scoop-windows/) and Git installed.

Related:[How to Install and Use the Scoop Windows Package Manager](https://adamtheautomator.com/scoop-windows/)

## Installing the Linux Sudo Windows Port

In recent years, the power of Sudo, an essential open-source tool, has been ported to Windows. As a result, a more comprehensive suite of tools for everyday IT tasks has been created. But still, Sudo does not come installed with your Windows system by default.

To install Sudo for Windows, follow these steps:

1\. Launch PowerShell, and execute the following `scoop` command to update Scoop.

This command ensures that Scoop, the package manager for Windows (like apt for Ubuntu), is up to date with the latest packages and dependencies.

Related: [Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

```powershell
scoop update
```

![Updating Scoop](https://adamtheautomator.com/wp-content/uploads/2023/06/image-111.png)

Updating Scoop

2\. Once updated, run the below command to `install` `sudo` for Windows.

```powershell
scoop install sudo
```

![Installing Sudo for Windows](https://adamtheautomator.com/wp-content/uploads/2023/06/image-110.png)

Installing Sudo for Windows

3\. Lastly, run the sudo command below without arguments to verify the installation.

```powershell
sudo
```

The output of the sudo usage statement below confirms that Sudo has been successfully installed.

![Verifying the Sudo installation](https://adamtheautomator.com/wp-content/uploads/2023/06/image-109.png)

Verifying the Sudo installation

## Elevating Privileges with Sudo in PowerShell

With Sudo installed on your Windows system, you can now use its functionality within your PowerShell scripts. Sudo comes in handy when executing commands requiring administrative privileges, but the shell currently runs with regular user privileges.

In such cases, you would need to restart PowerShell as administrator to proceed. But with Sudo, you can execute commands with elevated privileges without restarting the shell. This efficiency is similar to the functionality provided by the `sudo` command in Linux.

Related:[Discover How to Run PowerShell as Administrator](https://adamtheautomator.com/powershell-run-as-administrator/)

To see how Sudo works in PowerShell, below are some examples that let you invoke a PowerShell command with administrator privileges:

1\. Execute the following [`Set-Content`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content) command as a regular user.

This command appends the content value of `127.0.0.1 localhost` to the file called _`hosts2`_ in the `C:\Windows\System32\drivers\etc` directory.

```powershell
Set-Content -Path C:\Windows\System32\drivers\etc\hosts2 -Value "127.0.0.1 localhost"
```

Related:[Set-Content: The PowerShell Way to Write to a File](https://adamtheautomator.com/powershell-write-to-file/)

Below, the command fails and gives out an “Access Denied” error. This error is expected since opening and editing the _hosts2_ file in _C:\\Windows\\System32\\drivers\\etc_ requires administrator privileges.

![Attempting to append a file content that required administrator privileges](https://adamtheautomator.com/wp-content/uploads/2023/06/image-114.png)

Attempting to append a file content that required administrator privileges

2\. Next, execute the same command below, but this time, as an administrator by appending `sudo`.

```powershell
sudo Set-Content -Path C:\Windows\System32\drivers\etc\hosts2 -Value "127.0.0.1 localhost"
```

Notice that the command provides no output, which indicates the execution is successful and the desired content has been appended to the _hosts2_ file without error.

![Appending content to hosts2 file as an administrator (sudo)](https://adamtheautomator.com/wp-content/uploads/2023/06/image-113.png)

Appending content to _hosts2_ file as an administrator (`sudo`)

3\. Now, run the [`Get-Content`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content) command below to view the content of the _hosts2_ file.

```powershell
Get-Content -Path C:\Windows\System32\drivers\etc\hosts2
```

Related:[PowerShell Get-Content a PowerShell Tail Equivalent](https://adamtheautomator.com/powershell-get-content/)

You will see that the **127.0.0.1 localhost** line was added to the _hosts2_ file, as shown below.

This output confirms that Sudo works as intended in elevating privileges when you run a PowerShell command.

![Verifying the successful execution of the sudo command](https://adamtheautomator.com/wp-content/uploads/2023/06/image-112.png)

Verifying the successful execution of the `sudo` command

## Installing and Using `gsudo` as an Alternative to `sudo`

Enjoying `sudo` so far? In addition, an alternative to `sudo` called `gsudo` provides some advantages. For example, `gsudo` can detect your current shell and elevate privileges accordingly, treating commands as native shell commands.

This feature makes `gsudo` compatible with various shells, such as CMD, PowerShell, WSL, git-bash, and more. But like `sudo`, you must first install `gsudo` before you can use it to elevate privileges.

Related:[Getting Started with Git Bash Commands on Windows](https://adamtheautomator.com/git-bash-commands/)

To install and use `gsudo` on Windows, follow the steps below:

1\. Run the following command to sets the execution policy to `RemoteSigned` (if not already set).

This command ensures the TLS 1.2 protocol (`Tls12`) is used, downloads, and executes the `gsudo` installation script (`installgsudo.ps1`) from the specified URL.

```powershell
PowerShell -Command "Set-ExecutionPolicy RemoteSigned -scope Process; [Net.ServicePointManager]::SecurityProtocol = 'Tls12'; iwr -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | iex"
```

![Installing gsudo on Windows](https://adamtheautomator.com/wp-content/uploads/2023/06/image-117.png)

Installing `gsudo` on Windows

2\. Next, execute the below `gsudo` command to check the version installed.

```powershell
gsudo --version
```

The output below confirms you have installed `gsudo` on your Windows system. At this point, you can already use `gsudo` as an alternative to `sudo`.

But still, you must test if `gsudo` works as intended (step three).

![Checking the installed version of gsudo](https://adamtheautomator.com/wp-content/uploads/2023/06/image-116.png)

Checking the installed version of `gsudo`

3\. Execute the command below to open the `hosts2` file in `notepad`.

When you run the command, `gsudo` automatically detects your current shell and elevates the command accordingly.

```powershell
gsudo notepad C:\Windows\System32\drivers\etc\hosts2
```

![Using gsudo as an alternative to sudo](https://adamtheautomator.com/wp-content/uploads/2023/06/image-1.gif)

Using `gsudo` as an alternative to `sudo`

4\. Lastly, edit the _hosts2_ file and save the changes.

If you open the file with elevated privileges, saving the changes goes smoothly, as shown below.

![Saving changes to the hosts2 file ](https://adamtheautomator.com/wp-content/uploads/2023/06/image.gif)

Saving changes to the _hosts2_ file

But without using `gsudo` to open the file, the following message pops up when you save the changes.

![Saving the hosts2 file changes without elevated privileges](https://adamtheautomator.com/wp-content/uploads/2023/06/image-115.png)

Saving the _hosts2_ file changes without elevated privileges

## Conclusion

In this tutorial, you have learned to install and configure the Linux Sudo Windows port in PowerShell. With Sudo installed, you can now effortlessly execute administrative commands from your regular user shell, eliminating the need to restart as an administrator.

Besides `sudo`, you also learned to use `gsudo` as an alternative command that offers advanced features, such as automatic shell detection and treating commands as native shell commands.

This tutorial is just the beginning of your journey. Continue expanding your expertise. Why not create PowerShell aliases for `sudo` and `gsudo` commands to make them easier to use?

Related:[Setting Aliases for Quick Commands and Functions Accessibility](https://adamtheautomator.com/powershell-profile-a-getting-started-guide/#Setting_Aliases_for_Quick_Commands_and_Functions_Accessibility)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fsudo-windows-port%2F&text=How%20to%20Integrate%20the%20Linux%20Sudo%20Windows%20Port%20and%20PowerShell)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fsudo-windows-port%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fsudo-windows-port%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b81e69730da4c690758c2/4afeea42b7f854d23285b281664351779f042510f1e3a1d766d02cfa39b711a8.jpg)

### [Find and Disable Every Inactive AD Computer with PowerShell](/find-inactive-computers-active-directory/)

Find inactive computer accounts in Active Directory with Search-ADAccount, then disable and quarantine them with PowerShell in steps you can undo.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b814eba23fbf8d18b64a2/ade916ad78256face2456a10aacfbb82051f4957bf03d6f163193b25395e5183.jpg)

### [Back Up and Restore Every Group Policy Object in PowerShell](/backup-restore-gpos-powershell/)

Back up every Group Policy Object with Backup-GPO, restore one or all with Restore-GPO, and recover a deleted GPO with Import-GPO and New-GPLink.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b8181be1be294c37c6724/0ba6a36aaba4a30390fca48d395a19d38846d030302d345372b68b077c3a5cdc.jpg)

### [Find Stuck DFS Replication Backlogs with PowerShell](/dfs-replication-backlog-powershell/)

Find out whether DFS Replication is caught up. Get-DfsrBacklog reads the full file count past the 100-file limit, then a loop checks every group.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
