[Tutor] SSH commands in Python on Linux

Alan G alan.gauld at freenet.co.uk
Wed Aug 10 23:59:17 CEST 2005

import os
os.system( 'ssh root at "ls"' )

system is probably the wrong thing to use here since it doesn't 
return any output only a final error code.

> 1- Is there a way to not be asked for the root password?

Yes but you need to set up user security keys and such. 
The ssh man pages explain it in fairly dense detail.

> 2- If not, then is it possible to feed the SSH password 
> input with my Python script? 

Yes but you probably need the python version of expect module.
Not part of the standard library but available on source-forge 
I believe.

Alan G.

More information about the Tutor mailing list