Search code examples
pythonsshsubprocesspopen

SSH using subprocess.popen, unable to enter password


I HAVE to use SUBPROCESS for SSH 'cuz can't change from python 3.1(which unfortunately have virtually NO support for ssh libraries) due to project restrictions.

I have installed openSSH on both local and remote machine running over windows.

Problem: I am able to attempt ssh but NOT able to enter password and subsequent command e.g. dir and fetch result.

proc = subprocess.Popen("ssh -t -t remote_ip_here\n", shell = False, stdin = subprocess.PIPE, stdout=subprocess.PIPE)
#Entering password
proc.stdin.write(bytes("abc123\n","utf-8"))
#entering command
self.text , self.error = proc.communicate() // here I tried readlines() but it didnt returned any response.
print(self.text.decode("utf-8"))
proc.stdin.write(bytes("dir\n","utf-8"))

Any clue?


Solution

  • Sending a password over SSH or SCP with subprocess.Popen

    As you want to use windows you should look at a pexpect port: https://bitbucket.org/geertj/winpexpect/wiki/Home