[Tutor] SSH commands in Python on Linux

Martin Walsh mwalsh at groktech.org
Wed Aug 10 22:04:42 CEST 2005


Bernard Lebel wrote:
> Hello,

Hi Bernard,

> I'm trying to make a script to send a SSH command from a Linux
> computer to another Linux compter.
> 
> The Python syntax I'm using...
> 
> 
> import os
> os.system( 'ssh root at 192.168.10.204 "ls"' )
> 
> 
> Now the problem is that I'm always asked for the password. So my
> question is two-fold:
> 
> 1- Is there a way to not be asked for the root password?
> 2- If not, then is it possible to feed the SSH password input with my
> Python script? I have about stdin redirection, but I have to admit
> that I'm a bit lost and I don't know if it applies to SSH input as
> well.

you might also have a look at the pexpect module, found here:
http://pexpect.sourceforge.net/, I've found it to be a very useful tool
for working with interactive shell apps. There are a few ssh examples
provided in a separate download (pexpect-examples.tgz
http://sourceforge.net/project/showfiles.php?group_id=59762)

HTH,
Marty


More information about the Tutor mailing list