Guest User

Untitled

a guest
Mar 31st, 2018
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. The below python script is use to auto login on jump server from local system and form tunnel with storage box without any addition package on any servers
  2. Install paramiko module on local machine.
  3. Run the below script from local machine.
  4. import paramiko
  5. from sshtunnel import SSHTunnelForwarder
  6. with SSHTunnelForwarder(
  7. ('servername', 22), #jump server address
  8. ssh_username='ajay.prajapati',
  9. ssh_pkey=paramiko.RSAKey.from_private_key_file("/root/.ssh/id_rsa"),
  10. #ssh_private_key_password="*******",
  11. remote_bind_address=("*.*.*.*", 22), #storage box ip address
  12. local_bind_address=('127.0.0.1', 10023)
  13. ) as tunnel:
  14. client = paramiko.SSHClient()
  15. #client.load_system_host_keys()
  16. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17. client.connect(hostname='127.0.0.1', username="root", password="****", port=10023, look_for_keys=False)
  18. # do some operations with client session
  19. stdin, stdout, stderr = (client.exec_command('./datapull.sh')) # it will run the datapull.sh which is on storage box.
  20. print stdout.readlines()
  21. print stderr.readlines()
  22. client.close()
Add Comment
Please, Sign In to add comment