Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Connect to a host with specified public key
- # Failure will raise paramiko.ssh_exception.BadHostKeyException w00p w00p!
- import paramiko
- import base64
- host = 'localhost'
- port = '8022'
- keytype = 'ssh-rsa'
- host_key_b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDKwtRsDG4PpErhl0orhYZ6GLb/xPk81hUm7QWDMbAt3BKz1GrTnbZ0VZjmDE/joXVs6cNt9UvFvpVymwbx2IdqY9qN4DrWpZtzQ4l1asgcGGVbzX0wj2r6ZJbm9AhPW9WDZ4Ke/Hwbs/MxxKkEuQYRJekfnFTO1zRu1xyptwuLCS6P+Y79W+EiFLV8/9jZHjRlcpD+Fi4K0NSluDOrXw6Zn5XqXPSAYYkAOQnFGTfZuOGu5iyK1KVEGO7YS1WCAqnmyVF1RqJI1ehEUqjhqd8UYlD0Uq7KlPuA+EIzsDdEZ9vhMEbPBf0tgh9Lt+3UaTFNTGsdoDSdWuM13v+BR463'
- username = 'root'
- password = 'root'
- key = paramiko.RSAKey(data=base64.b64decode(host_key_b64))
- client = paramiko.SSHClient()
- #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
- client.get_host_keys().add('[%s]:%s' % (host, port), keytype, key)
- client.connect(host, port=port, username=username, password=password)
- stdin, stdout, stderr = client.exec_command('ls')
- for line in stdout:
- print('... ' + line.strip('\n'))
- client.close()
Add Comment
Please, Sign In to add comment