simplify the "simple" demo.
This commit is contained in:
parent
adb349bf2b
commit
a0313a47e4
|
@ -59,43 +59,26 @@ if username == '':
|
||||||
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
||||||
|
|
||||||
|
|
||||||
# get host key, if we know one
|
# now, connect and use paramiko Client to negotiate SSH2 across the connection
|
||||||
hostkeytype = None
|
|
||||||
hostkey = None
|
|
||||||
try:
|
try:
|
||||||
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
|
client = paramiko.SSHClient()
|
||||||
except IOError:
|
client.load_system_host_keys()
|
||||||
try:
|
client.set_missing_host_key_policy(paramiko.WarningPolicy)
|
||||||
# try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
|
print '*** Connecting...'
|
||||||
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
client.connect(hostname, port, username, password)
|
||||||
except IOError:
|
chan = client.invoke_shell()
|
||||||
print '*** Unable to open host keys file'
|
print repr(client.get_transport())
|
||||||
host_keys = {}
|
|
||||||
|
|
||||||
if host_keys.has_key(hostname):
|
|
||||||
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(username=username, password=password, hostkey=hostkey)
|
|
||||||
chan = t.open_session()
|
|
||||||
chan.get_pty()
|
|
||||||
chan.invoke_shell()
|
|
||||||
print '*** Here we go!'
|
print '*** Here we go!'
|
||||||
print
|
print
|
||||||
interactive.interactive_shell(chan)
|
interactive.interactive_shell(chan)
|
||||||
chan.close()
|
chan.close()
|
||||||
t.close()
|
client.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
t.close()
|
client.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in New Issue