Skip to main content

The missing sudo command for win32

Project description

sudo-win32

This missing sudo command for win32. This is a thin wrapper over gsudo. Check out the excellent repo here.

The only benefit for this repo is that you don't need administrator privledges in order to use this tool, while using something like choco install gsudo requires admin privledges. stderr/stdout and process return values are all supported. If you want to use gsudo directly, you can install it with choco install gsudo.

The most recent gsudo version used is 2.0.4

Linting Tests

Usage

> pip install sudo_win32[sudo]
> sudo taskkill /F /im wslservice.exe

If you omit [sudo] then the command will just be sudo_win32.

Documentation

This is shamelessly ripped from the gsudo repo and is kept as-is. Simply replace gsudo with sudo_win32 or sudo if you installed with the [sudo] extra. Otherwise it's the same.

Usage

gsudo [options]                  # Elevates your current shell
gsudo [options] {command} [args] # Runs {command} with elevated permissions
gsudo cache [on | off | help]    # Starts/Stops a credentials cache session. (less UAC popups)
gsudo status                     # Shows current user, cache and console status.
gsudo !!                         # Re-run last command as admin. (YMMV)
New Window options:
 -n | --new            # Starts the command in a new console/window (and returns immediately).
 -w | --wait           # When in new console, wait for the command to end.
 --keepShell           # After running a command, keep the elevated shell open.
 --keepWindow          # After running a command in a new console, ask for keypress before closing the console/window.

Security options:
 -u | --user {usr}     # Run as the specified user. Asks for password. For local admins shows UAC unless '-i Medium'
 -i | --integrity {v}  # Specify integrity level: Untrusted, Low, Medium, MediumPlus, High (default), System
 -s | --system         # Run as Local System account (NT AUTHORITY\SYSTEM).
 --ti                  # Run as member of NT SERVICE\TrustedInstaller
 -k                    # Kills all cached credentials. The next time gsudo is run a UAC popup will be appear.

Shell related options:
 -d | --direct         # Skips Shell detection. Asume CMD shell or CMD {command}.
 --loadProfile         # When elevating PowerShell commands, load user profile.

Other options:
 --loglevel {val}      # Set minimum log level to display: All, Debug, Info, Warning, Error, None
 --debug               # Enable debug mode.
 --copyns              # Connect network drives to the elevated user. Warning: Verbose, interactive asks for credentials
 --copyev              # (deprecated) Copy environment variables to the elevated process. (not needed on default console mode)

Note: You can use anywhere the sudo alias created by the installers.

Examples:

gsudo   # elevates the current shell in the current console window (Supports Cmd/PowerShell/Pwsh Core/Yori/Take Command/git-bash/cygwin)
gsudo -n # launch the current shell elevated in a new console window
gsudo -n -w powershell ./Do-Something.ps1 # launch in new window and wait for exit
gsudo notepad %windir%\system32\drivers\etc\hosts # launch windows app

sudo notepad # sudo alias built-in

# redirect/pipe input/output/error example
gsudo dir | findstr /c:"bytes free" > FreeSpace.txt

gsudo config LogLevel "Error"          # Configure Reduced logging
gsudo config Prompt "$P [elevated]$G " # Configure a custom Elevated Prompt
gsudo config Prompt --reset            # Reset to default value

# Enable credentials cache (less UAC popups):
gsudo config CacheMode Auto

Development

To develop software, run . ./activate.sh

Windows

This environment requires you to use git-bash.

Linting

Run ./lint.sh to find linting errors using pylint, flake8 and mypy.

Release Notes

  • 1.0.9 - Allow strings or list[str] as command.
  • 1.0.8 - Fixes some commands in admin mode.
  • 1.0.7 - Use shell mode for gsudo, since it's a better experience. Commands are merged via subprocess.list2cmdline
  • 1.0.6 - Switch the implementation to gsudo, which is excellent and does everything this lib needs.
  • 1.0.5 - sudo-win32[sudo] now works correctly, before it was unconditionally installing.
  • 1.0.3 - The stdout/stderr are now correct re-routed back.
  • 1.0.2 - The return value of the command is now returned when elevating privledges.
  • 1.0.1 - Fixing the readme
  • 1.0.0 - Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sudo-win32-1.0.9.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

sudo_win32-1.0.9-py2.py3-none-any.whl (4.2 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file sudo-win32-1.0.9.tar.gz.

File metadata

  • Download URL: sudo-win32-1.0.9.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for sudo-win32-1.0.9.tar.gz
Algorithm Hash digest
SHA256 768b8ec8e824007cea3e163482cfc588f6e9806e2bd98f998e099e40eae0560e
MD5 747a67fc2e42ac835b4d86a07540f06d
BLAKE2b-256 f71c87c9aceb00d99829c351cc61cbd1a2d0006db69bcf158b4f4487c185f571

See more details on using hashes here.

File details

Details for the file sudo_win32-1.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: sudo_win32-1.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for sudo_win32-1.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 faa6d30e8c5d5c73b2bba7775f047f8a33ffad9bce01ab88d7f29c609faf5e81
MD5 b6b78c356dc232be6ed45424f0832943
BLAKE2b-256 8647cdadfdeec0dc6af6d7d95cf8539ed133c1c50eec342224e779243eeaea43

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page