Advertisement
Guest User

Untitled

a guest
Mar 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding:utf8 -*-
  3. # sources
  4. # 1. https://gist.github.com/tell-k/4943359#file-paramiko_proxycommand_sample-py-L11
  5. # 2. https://github.com/paramiko/paramiko/pull/97
  6. # info: http://bitprophet.org/blog/2012/11/05/gateway-solutions/
  7. # local -> proxy-server -> dest-server
  8. # ~/.ssh/config
  9. #
  10. # Host proxy-server
  11. # User hoge
  12. # HostName proxy.example.com
  13. # IdentityFile ~/.ssh/id_rsa_proxy
  14. #
  15. # Host dest-server
  16. # User fuga
  17. # HostName proxy.example.com
  18. # IdentityFile ~/.ssh/id_rsa_dest
  19. # ProxyCommand ssh proxy-server nc %h %p
  20. #
  21. import os
  22. import sys
  23. import paramiko
  24.  
  25. def test_client(host_name):
  26. conf = paramiko.SSHConfig()
  27. conf.parse(open(os.path.expanduser('~/.ssh/config')))
  28. host = conf.lookup(host_name)
  29. client = paramiko.SSHClient()
  30. client.load_system_host_keys()
  31. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  32.  
  33. client.connect(
  34. host['taurus.fis.agh.edu.pl'], username=host['2goral'],
  35. # if you have a key file
  36. # key_filename=host['identityfile'],
  37. password='Pervetprev93',
  38. sock=paramiko.ProxyCommand(host.get('ssh -A 2goral@taurus.fis.agh.edu.pl nc %h %p'))
  39. )
  40. stdin, stdout, stderr = client.exec_command('command to run on dest-host')
  41. print(stdout.read())
  42.  
  43. if __name__ == '__main__':
  44. test_client('lhcbgpu1')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement