mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

sudo: sorry, you must have a tty to run sudo #1

Closed kgn closed 11 years ago

kgn commented 11 years ago

Is there a way to run sudo commands remotely with spur?

mwilliamson commented 11 years ago

I'm assuming that running commands with a pseudo-terminal would be enough to satisfy sudo.

There's no way to do this directly at the moment. There might be some incantation to bash or similar that opens a tty, but I don't know off the top of my head.

Actually implementing this in spur is fairly straightforward for SSH -- you can just call channel.get_pty on the Paramiko Channel instance. Implementing this for local processes is a little trickier since it involves creating a pty using the pty module, and then hooking it up the process created by Popen.

mwilliamson commented 11 years ago

I've just added a use_pty argument to run and spawn -- could you try seeing if setting it to True does the trick? For instance:

shell = spur.SshShell(...)
shell.run(["sudo", "echo", "hello"], use_pty=True)
kgn commented 11 years ago

Hey sorry for the delay. I tried running this but it just hung, however I later found out this was due to a shell being opened that was waiting for the sudo password. Our sysadmin did something on the server with tty so it's working now but I cannot confirm if these changes would have gotten around the problem, sorry. Thanks for this update, hopefully it will help others.