7 ms·
Show HN: Sudo for Windows
- elsamuko 9y agoI'm using cygstart --action=runas This works well, too.
- robbyt 9y agoYeah, I'm never going to remember that one...
- sapphire_tomb 9y agoMaybe this will help? :) alias sudo="cygstart --action=runas"
- phs2501 9y agoThere's also a "sudo" for windows distributed as a chocolatey package that I've used for at least a year. Appears to do pretty much the same thing as this one. https://chocolatey.org/packages/Sudo https://chocolatey.org/packages/Sudo
- flukus 9y agoChocolatey is one of my biggest reasons to use this. Every single time I install something I forget to run as admin.
- kyriakos 9y agoThis is actually very useful, will save me time reopening terminal sessions
- dewiz 9y agoAll of this can be done with a bit of vbscript, no need to install anything
- ocdtrekkie 9y agoI've always been annoyed by the lack of ability for certain things to elevate as needed. Why doesn't Notepad offer to let you elevate when you try and save the hosts file? I can't count how often I relaunch Command Prompt to Run as Admin. But I'm hesitant to use a third party tool here, I really wish Microsoft just dealt with this properly.
- TokenDiversity 9y ago`Start-Process <stuff> -verb RunAs` in PS
- pjmlp 9y ago1 - Shift-Right Click on the executable, including links 2 - Select Run As...
- sllabres 9y agoIsn't this more like "su" instead of "sudo"? (and it would spare two key strokes ;)
- TokenDiversity 9y agoI don't understand Windows permissions well but if anybody looking to do this without a dpendencey.. I think `Start-Process <stuff> -verb RunAs` does the same
- deleted 9y ago[deleted]
- locusm 9y agoThere is also a sudo for scoop http://scoop.sh/ http://scoop.sh/
- ComodoHacker 9y agoIs it really sudo? Does it remember credentials somewhere for a limited time and across the whole system? If so, I cant see a way to implement it securely if you're not MS.
- skrebbel 9y agoThere's no true Scotsman, you know. This solves a real problem and it works great. There's no horrible issue with getting a UAC dialog every time you do a sudo command. After all, in Windows (for better or worse) you need to be Administrator for less stuff.
- huhtenberg 9y agoI'm guessing it spawns a persistent elevated process that processes commands passed to it by 'sudo' and that exits after a while when idle. No credentials need to be stored anywhere.
- pjmlp 9y agoNice as a learning project, but RunAs is already supported at CLI and GUI level, since several versions. For those without much Windows GUI-fu, shift-right click.
- deleted 9y ago[deleted]
- mattn_jp 9y agorunas request password. And I don't want to touch my mouse. Many of implementation doesn't handle stdin/stdout/stderr.
- Jaruzel 9y agoYou can call 'runas' via an API at code level that allows you to specify a password. There's quite a few tools out there that do it. I used to host mine on my website but it caused all those website classification systems to classify my domain as 'hacking tools' so I had to remove it. :(
- mattn_jp 9y agoIf you allow you to enter a password, you can use runas.exe which is provided by Microsoft.
- Jaruzel 9y agoRunAs.exe only allows you enter a password interactively. If you want to elevate with RunAs in a script and pre-specify the password[1], you can't do it. -- [1] Yes, I know this is awful security, but sometimes you have no choice.
- pawadu 9y ago> You can call 'runas' via an API at code level that allows you to specify a password. Wait, then where does the whole UAC thing comes from??
- 9y ago
- mattn_jp 9y agoHi, all. I'm author. I added this because I want to write hosts file with ":w !sudo tee %" from gvim.exe on Windows. But most of implementations doesn't work for this.
- eps 9y agoYou should probably clarify in the Readme that your sudo remembers the credentials or this thread will overflow with runas alternative suggestions.
- Jaruzel 9y agoI literally wrote something identical just over a week ago; even called it sudo as well. Mine's in .NET as a little EXE. It's about 10 lines of code. I am not dissing this effort though. Far from it. Open Source is cool. It's annoying that you still have to navigate the UAC dialog though - not sure how to get around that, without compromising security. For those talking about right-click on the EXE... If you live in the command prompt, having to reach for the mouse just to elevate is irritating as hell.
- eps 9y agoThe main point of sudo is that it eliminates the need to enter the password for a while. Does your "something identical in 10 lines" do that?
- Jaruzel 9y agoIt's obviously how I word things... :( Why are you focusing on my '10 lines' comment? It's not a competition. I only stated the line amount as it's quite a trivial problem to solve, but as others have asked - why is it not a command by default in Windows?
- blauditore 9y ago> The main point of sudo is that it eliminates the need to enter the password for a while. I disagree, that's just an additional feature of it. The main point is that you can carry out admin tasks from an otherwise more restricted environment, so you only elevate your power when necessary. Otherwise, users might be tempted to always run whole sessions as an admin/root for convenience.
- Andoryuuta 9y agoI mean, you can easily bypass the UAC dialog by duplicating the token of a already elevated process. Here is an example of this I saw before in powershell: https://gist.github.com/tyranid/9ffef5962a642d4a1bb8e4ee7e3bebc5 https://gist.github.com/tyranid/9ffef5962a642d4a1bb8e4ee7e3b...
- 9y ago
- Grom_PE 9y agoI just use this 6 kb no-dependencies command line program: http://code.kliu.org/misc/elevate/ http://code.kliu.org/misc/elevate/
- deleted 9y ago[deleted]
- mattn_jp 9y agoI read the code. I don't make sure but AFAIS, elevate doesn't handle stdin/stdout/stderr, can't pass environment variable correctly. After set FOO=bar, the process can't read FOO. etc.
- stinos 9y agoIf you're at the command line anyway, Powershell is nearly always a better choice, and it has that covered also. See TokenDiversity 's comment, or use a simple function or use Invoke-Elevated from an installable package. E.g. https://stackoverflow.com/questions/1566969/showing-the-uac-prompt-in-powershell-if-the-action-requires-elevation https://stackoverflow.com/questions/1566969/showing-the-uac-... Or if you know the admin account you could use something like Invoke-Command -ScriptBlock { ls } -ComputerName $env:COMPUTERNAME -Credential (Get-Credential)
- jhasse 9y ago> Powershell is nearly always a better choice Not if I want resemblance with Bash-like shells. I guess that's also the point of this: Most people already know sudo from Linux and cmd.exe, now they can use both together.
- nailer 9y ago20 year bash user and recent Powershell convert here. Powershell has proper things like profiles and aliases, cool stuff like being able to cd and rm the Environment and Registry keys like files. cmd has none of those. (Plus powershells structured output so you can use 'where' and 'select' and 'get-member' rather than scraping with regexs. )
- posguy 9y agoBut why saddle myself with a registry? I just don't see the need. Also, basic stuff like tab completion and so forth just doesn't exist in Powershell, copying/pasting is a nightmare, and it has its own syntax tomfoolrey like opening Internet Exploder when I just wanna download a damn file via CLI! It isn't that hard to build a decent shell, if zsh can do it, why can't MS put a few decent interns on it and get their act together? I feel like I'm knocking skulls together whenever I end up talking Powershell with someone from across the lake here in Seattle, this stuff isn't all that difficult!
- 9y ago
- yread 9y agoThere is also CPAU where you can store the elevated command as a sort of batch file http://www.joeware.net/freetools/tools/cpau/ http://www.joeware.net/freetools/tools/cpau/