Python Script to SSH
<p>I am a beginner trying to do SSH writing a basic code, I have tried everything not able to debug this , My code is as follows :</p>

<pre><code>import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ("1")
ssh.connect('196.5.5.6', username='abc', password='abc')
print ("2")
stdin, stdout, stderr = ssh.exec_command('show version')
print ("3")
output= stdout.readlines()
print ("4")
print(output)
</code></pre>

<p>Output I get is 1<br>
2<br>
3

<br>
At 4 it get's stuck somewhere , there is problem that I am not able to fetch the data , Please help anyone. Code just hangs at the output step. Everywhere the solution is totally same.</p>

<p>You don't need to do <code>readlines(</code>) on <code>stdin</code>. You can print it directly. <code>readlines()</code> expect a file to be opened and read from the file. Whereas <code>stdin</code>, <code>stdout</code>, <code>stderr</code> are not files, rather a block of strings ( or string buffer used in paramiko channel). If you check the type of <code>stdin</code>, <code>stdout</code>, <code>stderr</code>, you will find <code>&lt;class 'paramiko.channel.ChannelFile'&gt;</code>, which are not exactly files, but are file like objects created to store the buffers in paramiko channel. </p>

<pre><code>import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print 1
ssh.connect('196.5.5.6', username='abc', password='abc')
print 2
stdin, stdout, stderr = ssh.exec_command('show version')
print 3
output= stdin
print 4
print(output)
print '---', stdout
print '---==', stderr
</code></pre>

python shell ssh