title: Python ssh to a server having a username and password to login using subprocess only
body: <p>There is text file called ip_addresses.txt containing 3 IP addresses:</p>
  
  <pre><code>192.x.x.x
  192.x.x.x
  192.x.x.x
  </code></pre>
  
  <p>I want to ssh to all of these servers and execute a shell command. 
  Here is code snippet:</p>
  
  <pre><code>ip = open("ip_addresses.txt", "r")
  data = ip.readlines()
  for ips in data:
      ips = ips.strip("\n")
      ssh = subProcess.Popen(["ssh", "%s" % ips], stdin = subprocerss.PIPE, stdout= subprocess.PIPE, stderr =subprocess.PIPE)
  ssh.stdin.write("ls -ltr")
  result = ssh.stdout.readlines()
  if result == []:
      error = ssh.stderr.readlines()
      print &gt;&gt;sys.stderr, "ERROR: %s" %error
  else:
      print result
  </code></pre>
  
  <p>But to ssh make a ssh connection to these servers, I have to provide a <code>username</code> and <code>password</code> too, which are <code>root</code> and <code>sam@123</code>. How can I provide these details as well and check a successful login to the servers.</p>
  
  <p>Thanks</p>