Interacting with a spawned ssh session?

Donn Cave donn at oz.net
Wed Jan 17 02:10:41 EST 2001


Quoth "Steven M. Castellotti" <scastell at sas.upenn.edu>:
| 	I'm having two problems with one function.
|
| 	I want to be able to spawn an ssh session to another computer, and then
| interact with that session through python commands. (this is on a linux
| system)
|
| 	The first problem is feeding the password to ssh; I believe that it
| wants it's own tty.
|
| 	The second problem, and currently the more pressing one, is how to best
| send commands to that ssh session, and read back/parse the results.
|
| 	I've looked at the pty module, but must not be understanding its
| functionality, as I can't get a pty.fork()'d file descriptor to allow me
| to perform commands. I'd like to keep away from popen (for security
| reasons, though I'm not certain any other method could be considered
| secure either), but am still having trouble interacting with the spawned
| process (in this case a telnet session; for simplicity).
|
| 	Can anyone provide me with, or point me to, any examples of how to use
| python to do roughly what I'm describing?

I don't have anything at hand, but think it might help to mention
that there's old pty functionality in Python 1.5, and newer stuff
in 2.0.  If you haven't upgraded to 2.0, this would be a good time
to think about it.  As for pty.fork(), I guess I wouldn't expect
it to allow you to perform commands, so to speak, because it
doesn't exec any command interpreter.  spawn() might be more useful.

And of course for the obligatory anti-password message, instead
of RSA keys I like Kerberos authentication, and that will work
with ssh, telnet etc. if your site is enlightened enough to support
Kerberos 5.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list