There's no 'sudo' command in Cygwin
Because there's no sudo command in Cygwin, scripts that I want to run fail with
./install.sh: line N: sudo: command not found
What's the standard way for getting around this? Editing the scripts to remove sudo
? Getting some sudo
-like tool for Windows?
Solution 1:
I wrote the (rather simple) TOUACExt for SUDO for CygWin, a pre-beta shell script automation that approaches to the behavior of classical sudo
for Linux:
- Open and closes automatically sudoserver.py when needed.
- Requests UAC Elevation Prompt.
Installation requires copying the four .sh
scripts to some path directory, creating an alias and just a few more steps detailed in the thread.
The results: you type a single sudo YourCommand
and you get the output of it, without having to worry about the rest of the process.
Solution 2:
One way is to create a fake "sudo" command with the following content:
#!/usr/bin/bash
"$@"
This will allow the install.sh
to continue, because sudo is found.
This doesn't elevate privileges like real sudo does. If you really need elevated privileges start cygwin shell with from an account with administrative privileges (XP) or r-click on cygwin.bat and "run as administrator" (Vista,Win7)
Solution 3:
I found the answer on the cygwin mailing list. To run command
with elevated privileges in Cygwin, precede the command with cygstart --action=runas
like this:
$ cygstart --action=runas command
This will open a Windows dialogue box asking for the Admin password and run the command if the proper password is entered.
This is easily scripted, so long as ~/bin
is in your path:
$ cat ~/bin/sudo
#!/usr/bin/bash
cygstart --action=runas "$@"
$ PATH=$HOME/bin:$PATH
$ chmod +x ~/bin/sudo
$ sudo elevatedCommand
Tested on 64-bit Windows 8.
Solution 4:
Building on dotancohen's answer I'm using an alias:
alias sudo="cygstart --action=runas"
Works as a charm for external programs (not shell built-ins, though):
sudo chown User:Group <file>