Guest User

Untitled

a guest
Jan 24th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import base64
  2. import paramiko
  3. #key = paramiko.RSAKey(data=base64.b64decode(b'nicekeyherefrommy.rsafolder'))
  4. client = paramiko.SSHClient()
  5. client.load_system_host_keys()
  6. client.set_missing_host_key_policy(paramiko.WarningPolicy())
  7.  
  8. #client.get_host_keys().add('druidia.com', 'ecdsa-sha2-nistp256', key)#'ssh-rsa', key)
  9. client.connect('druidia.com', username='pres_skroob', password='12345')
  10. stdin, stdout, stderr = client.exec_command('ls')
  11. for line in stdout:
  12. print('... ' + line.strip('n'))
  13. client.close()
  14.  
  15. import base64
  16. import paramiko
  17. import os
  18.  
  19. # get host key, if we know one
  20. hostkeytype = None
  21. hostkey = None
  22. hostname = "druidiia.com"
  23. Port=22
  24. username = "pres_skroob"
  25. password = "12345"
  26. try:
  27. host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
  28. except IOError:
  29. try:
  30. # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
  31. host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
  32. except IOError:
  33. print('*** Unable to open host keys file')
  34. host_keys = {}
  35.  
  36. print host_keys
  37.  
  38. if hostname in host_keys:
  39. hostkeytype = host_keys[hostname].keys()[0]
  40. hostkey = host_keys[hostname][hostkeytype]
  41. print('Using host key of type %s' % hostkeytype)
  42.  
  43.  
  44. # now, connect and use paramiko Transport to negotiate SSH2 across the connection
  45. try:
  46. t = paramiko.Transport((hostname, Port))
  47. #t.connect(hostkey, username, password, gss_host=self.hostname,gss_auth=UseGSSAPI, gss_kex=DoGSSAPIKeyExchange)
  48. t.connect(hostkey, username, password)
  49. sftp = paramiko.SFTPClient.from_transport(t)
  50. ...
  51. ...
  52. ...
  53. except Exception as e:
  54. print('*** Caught exception: %s: %s' % (e.__class__, e))
  55. traceback.print_exc()
  56. try:
  57. t.close()
  58. except:
  59. pass
  60. sys.exit(1)
  61.  
  62. <paramiko.hostkeys.HostKeys object at 0x21fefd0>
  63. Using host key of type ecdsa-sha2-nistp256
  64. *** Caught exception: <class 'paramiko.ssh_exception.AuthenticationException'>: Authentication failed.
  65. Traceback (most recent call last):
  66. File "sftptest2.py", line 68, in <module>
  67. traceback.print_exc()
  68. NameError: name 'traceback' is not defined
Add Comment
Please, Sign In to add comment