Search code examples
pythonsshterminalipod

Python output to terminal during ssh login


I have been looking everywhere for this and have not found a solution. I am using python 2.5.1 on an Apple iPod and I am trying to connect to a host with SSH. First I start off with import os. Next I os.system('ssh 192.168.1.13). After this command is executed I next try to os.system('password'). This does not work and SSH asks for the password, after I exit the SSH session then my password is printed. Is there any way that I can get it so that it sends the password to SSH? I don't want to add any other modules to python. Thanks!

Complete file:

import os

os.system('ssh 192.168.1.13')
os.system('password')

Solution

  • take a look at pexpect, it should do the trick in the manner you expect it.

    Example from the docs:

    child = pexpect.spawn('scp foo myname@host.example.com:.')
    child.expect ('Password:')
    child.sendline (mypassword)
    

    Yes, that's yet another module.. but the cleanest way to accomplish what you want.