1

I have written a below script to do ssh and providing password .But it still waits for password prompt while running . Searched through many such questions on stack overflow, Everyone suggesting to use paramiko or pexpect but I can not use this as this script has to be run by many people on different machines and can not ask everyone to install these libraries first

Looking for a solution without using such libraries

import subprocess
import sys 

HOST="lab@xxxx"
COMMAND="pwd"

ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND], shell=False, stdout=subprocess.PIPE, stdin = subprocess.PIPE, stderr=subprocess.PIPE)

ssh.stdin.write('lab\n')
ssh.stdin.flush()
result = ssh.stdout.readlines()
if result == []: 
    error = ssh.stderr.readlines()
    print >>sys.stderr, "ERROR: %s" % error
else:
    print result

~

1
  • I suggest you use pem files for authentication as using ssh with password, especially with the raw characters of the password in a script. Commented Feb 8, 2017 at 6:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.