title: Running Sudo Command with paramiko
body: <p>I am trying to execute a sudo command on a remote machine using python-paramiko, when I execute the command, I bind it with 3 streams, and I use the input stream to pass the password, but it doesn't work, this is the traceback result:</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;input&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python2.7/dist-packages/paramiko/file.py", line 314, in write
  self._write_all(data)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/file.py", line 439, in _write_all
  count = self._write(data)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 1263,in _write
  self.channel.sendall(data)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 796, in sendall
  raise socket.error('Socket is closed')
  error: Socket is closed
  </code></pre>
  
  <p>and this is my python code:</p>
  
  <pre><code>import paramiko
  ssh = paramiko.SSHClient()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh.connect('192.168.0.104', username='cdc',password='123456')
  stdin, stdout, stderr = ssh.exec_command("sudo dmesg")
  stdin.write("123456\n")
  stdin.flush()
  print stdout.readlines()
  ssh.close()
  </code></pre>
  
  <p>Any help? Thanks in advance</p>