Using python with SSH?

Jp Calderone exarkun at intarweb.us
Wed Dec 17 19:25:42 EST 2003


On Thu, Dec 18, 2003 at 12:08:43AM +0100, Lawrence Oluyede wrote:
> Steve <nospam at nopes> writes:
> 
> > ssh -l user host "/path/to/program"
> >
> > prompts for a password and I don't know how to supply one via a python
> > script. Is there an easy way out? Can I log onto to the other machine via
> > ssh somehow? Does a python script support this? Thanks!
> 

  You could open ssh in a pty, or you could use a Python module that speaks
the SSH protocol, thus obviating the requirement to call out to the ssh
command line program.

  A couple choices for such modules:

    http:/www.twistedmatrix.com/

    http://www.lag.net/~robey/secsh/

> Try something like this:
> 
> import os
> 
> ssh_pipe = os.popen("ssh -l user path")
> ssh_pipe.write(password)
> ssh_pipe.write("\n")
> ssh_pipe.flush()
> ssh_pipe.close()
> 
> hope this helps

  It does not.  ssh won't accept a password from standard input, it requires
it to be entered into the terminal.

  Jp





More information about the Python-list mailing list