Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import paramiko
- #key = paramiko.RSAKey(data=base64.b64decode(b'nicekeyherefrommy.rsafolder'))
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.set_missing_host_key_policy(paramiko.WarningPolicy())
- #client.get_host_keys().add('druidia.com', 'ecdsa-sha2-nistp256', key)#'ssh-rsa', key)
- client.connect('druidia.com', username='pres_skroob', password='12345')
- stdin, stdout, stderr = client.exec_command('ls')
- for line in stdout:
- print('... ' + line.strip('n'))
- client.close()
- import base64
- import paramiko
- import os
- # get host key, if we know one
- hostkeytype = None
- hostkey = None
- hostname = "druidiia.com"
- Port=22
- username = "pres_skroob"
- password = "12345"
- try:
- host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
- except IOError:
- try:
- # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
- host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
- except IOError:
- print('*** Unable to open host keys file')
- host_keys = {}
- print host_keys
- if hostname in host_keys:
- hostkeytype = host_keys[hostname].keys()[0]
- hostkey = host_keys[hostname][hostkeytype]
- print('Using host key of type %s' % hostkeytype)
- # now, connect and use paramiko Transport to negotiate SSH2 across the connection
- try:
- t = paramiko.Transport((hostname, Port))
- #t.connect(hostkey, username, password, gss_host=self.hostname,gss_auth=UseGSSAPI, gss_kex=DoGSSAPIKeyExchange)
- t.connect(hostkey, username, password)
- sftp = paramiko.SFTPClient.from_transport(t)
- ...
- ...
- ...
- except Exception as e:
- print('*** Caught exception: %s: %s' % (e.__class__, e))
- traceback.print_exc()
- try:
- t.close()
- except:
- pass
- sys.exit(1)
- <paramiko.hostkeys.HostKeys object at 0x21fefd0>
- Using host key of type ecdsa-sha2-nistp256
- *** Caught exception: <class 'paramiko.ssh_exception.AuthenticationException'>: Authentication failed.
- Traceback (most recent call last):
- File "sftptest2.py", line 68, in <module>
- traceback.print_exc()
- NameError: name 'traceback' is not defined
Add Comment
Please, Sign In to add comment