title: Nested SSH using Python Paramiko
body: <p>I have this scenario:</p>
  
  <p>Local-host --------- jump-host ------- target-machine</p>
  
  <p>I am trying to write a code in Python using Paramiko to first SSH from local-host to jump-host and then SSH from jump-host to the target-machine.
  From the target-machine, I want to capture some outputs and store them locally either as a variable or as a file (haven't got to that point yet).
  I found an example from Stack Overflow where they talk about using nested SSH with Paramiko, and I follow it but I get stuck here:</p>
  
  <p>My code:</p>
  
  <pre><code>enter code here
  
  #!/usr/bin/python
  #
  # Paramiko
  #
  import paramiko
  import sys
  import subprocess
  #
  # we instantiate a new object referencing paramiko's SSHClient class
  #
  vm=paramiko.SSHClient()
  vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  vm.connect('192.168.115.103',username='osmanl',password='xxxxxx')
  #
  vmtransport = vm.get_transport()
  dest_addr = ('192.168.115.103', 22)
  local_addr = ('127.0.0.1', 22)
  vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
  #
  jhost=paramiko.SSHClient()
  jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  jhost.load_host_keys('/home/osmanl/.ssh/known_hosts')
  jhost.connect('10.103.53.26', username='latiu', password='xxxx', sock=vmchannel)
  #
  stdin, stdout, stderr = rtr.exec_command("show version | no-more")
  #
  print stdout.readline()
  #
  jhost.close()
  vm.close()
  # End
  </code></pre>
  
  <hr>
  
  <p>When I run the above, I get this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ python sshvm.py
  Traceback (most recent call last):
    File "sshvm.py", line 28, in &lt;module&gt;
      jhost.load_host_keys('/home/osmanl/.ssh/known_hosts')
    File "/usr/lib/python2.7/site-packages/paramiko-1.15.2-py2.7.egg/paramiko/client.py", line 121, in load_host_keys
      self._host_keys.load(filename)
    File "/usr/lib/python2.7/site-packages/paramiko-1.15.2-py2.7.egg/paramiko/hostkeys.py", line 94, in load
      with open(filename, 'r') as f:
  IOError: [Errno 2] No such file or directory: '/home/osmanl/.ssh/known_hosts'
  </code></pre>