Guest User

Untitled

a guest
Sep 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Connect to a host with specified public key
  3. # Failure will raise paramiko.ssh_exception.BadHostKeyException w00p w00p!
  4. import paramiko
  5. import base64
  6.  
  7. host = 'localhost'
  8. port = '8022'
  9. keytype = 'ssh-rsa'
  10. host_key_b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDKwtRsDG4PpErhl0orhYZ6GLb/xPk81hUm7QWDMbAt3BKz1GrTnbZ0VZjmDE/joXVs6cNt9UvFvpVymwbx2IdqY9qN4DrWpZtzQ4l1asgcGGVbzX0wj2r6ZJbm9AhPW9WDZ4Ke/Hwbs/MxxKkEuQYRJekfnFTO1zRu1xyptwuLCS6P+Y79W+EiFLV8/9jZHjRlcpD+Fi4K0NSluDOrXw6Zn5XqXPSAYYkAOQnFGTfZuOGu5iyK1KVEGO7YS1WCAqnmyVF1RqJI1ehEUqjhqd8UYlD0Uq7KlPuA+EIzsDdEZ9vhMEbPBf0tgh9Lt+3UaTFNTGsdoDSdWuM13v+BR463'
  11.  
  12. username = 'root'
  13. password = 'root'
  14.  
  15. key = paramiko.RSAKey(data=base64.b64decode(host_key_b64))
  16.  
  17. client = paramiko.SSHClient()
  18. #client.load_system_host_keys() # will cause to load from known_hosts - without this or get_host_keys().add() there will be NO known hosts
  19. client.get_host_keys().add('[%s]:%s' % (host, port), keytype, key)
  20.  
  21. client.connect(host, port=port, username=username, password=password)
  22. stdin, stdout, stderr = client.exec_command('ls')
  23. for line in stdout:
  24. print('... ' + line.strip('\n'))
  25. client.close()
Add Comment
Please, Sign In to add comment