Guest User

Untitled

a guest
Jun 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import paramiko
  4.  
  5. jumpHost=paramiko.SSHClient()
  6. sshKey = paramiko.RSAKey.from_private_key_file('path.to.key/file', password = 'the.passphrase')
  7. jumpHost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8. jumpHost.connect('jump.hostname',username='foo', pkey = sshKey)
  9. jumpHostTransport = jumpHost.get_transport()
  10. dest_addr = ('destination.hostname', 22)
  11. local_addr = ('jump.hostname', 22)
  12. jumpHostChannel = jumpHostTransport.open_channel("direct-tcpip", dest_addr, local_addr)
  13.  
  14. destHost=paramiko.SSHClient()
  15. destHost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  16. destHost.connect('destination.hostname', username='foo', sock=jumpHostChannel, pkey=sshKey)
  17. destHostAgentSession = destHost.get_transport().open_session()
  18. paramiko.agent.AgentRequestHandler(destHostAgentSession)
  19.  
  20. stdin, stderr, stdout = destHost.exec_command("my.command.which.connects.to.another.host")
  21.  
  22. print(stdout.read())
  23. print(stderr.read())
  24.  
  25. destHost.close()
  26. jumpHost.close()
Add Comment
Please, Sign In to add comment