need wrapper for ssh/scp

Thomas Wouters thomas at
Wed Mar 29 19:21:40 CEST 2000

On Wed, Mar 29, 2000 at 09:37:09AM -0700, Andrew Patterson wrote:

> Does anyone have a wrapper or example code that will allow me to use ssh
> and scp in a python script. Normally you would use some form of popen, but
> I can't seem to feed ssh/scp a passphrase.

ssh/scp (and indeed most programs that ask for a password) talk directly to
the tty when getting sensitive information (like the password or the
passphrase.) You can catch this by using the 'pty' module. You probably want
to pty.fork(), and then redirect stdin/stdout, and fiddle with the terminal
on both ends to easily pass the passphrase... You face the usual deadlock
problems though, when both ends of the pipe are waiting for the other to
send data.

I had fun with the pty module once, when I had to unzip roughly a hundred
.zip files, which were all password encrypted (with the same password.) The
pty module made my life a lot, lot easier ;)

Thomas Wouters <thomas at>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list