mirror of https://github.com/huashengdun/webssh
Update handler.py
Add SSH Agent key support.
Allows for SSH Agent use and key support if the local OS is setup for it thanks to Paramikos support of this.
Courtesy of this excerpt
ae3d0febef/demos/demo.py (L41-L59)
and my mod adding "allow_agent=True, look_for_keys=True," to the string
ssh.connect(*args, allow_agent=True, look_for_keys=True, timeout=options.timeout)
This is working perfectly for me on Linux project and should work in Windows as well.
http://docs.paramiko.org/en/stable/api/agent.html
This will allow for easy switching of servers and key management for those embedding into custom apps.
pull/144/head
parent
884ac27d5c
commit
a8f37c8d23
|
@ -67,6 +67,21 @@ class SSHClient(paramiko.SSHClient):
|
||||||
allowed_types = set()
|
allowed_types = set()
|
||||||
two_factor_types = {'keyboard-interactive', 'password'}
|
two_factor_types = {'keyboard-interactive', 'password'}
|
||||||
|
|
||||||
|
agent = paramiko.Agent()
|
||||||
|
agent_keys = agent.get_keys()
|
||||||
|
if len(agent_keys) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
for key in agent_keys:
|
||||||
|
logging.info("Trying ssh-agent key %s" % hexlify(key.get_fingerprint()))
|
||||||
|
try:
|
||||||
|
self._transport.auth_publickey(username, key)
|
||||||
|
logging.info("... success!")
|
||||||
|
return
|
||||||
|
except paramiko.SSHException as e:
|
||||||
|
logging.info("... nope.")
|
||||||
|
saved_exception = e
|
||||||
|
|
||||||
if pkey is not None:
|
if pkey is not None:
|
||||||
logging.info('Trying publickey authentication')
|
logging.info('Trying publickey authentication')
|
||||||
try:
|
try:
|
||||||
|
@ -438,7 +453,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
logging.warning('Could not detect the default ecnoding.')
|
logging.warning('Could not detect the default encoding.')
|
||||||
return 'utf-8'
|
return 'utf-8'
|
||||||
|
|
||||||
def ssh_connect(self, args):
|
def ssh_connect(self, args):
|
||||||
|
@ -447,7 +462,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
|
||||||
logging.info('Connecting to {}:{}'.format(*dst_addr))
|
logging.info('Connecting to {}:{}'.format(*dst_addr))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ssh.connect(*args, timeout=options.timeout)
|
ssh.connect(*args, allow_agent=True, look_for_keys=True, timeout=options.timeout)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
|
raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
|
||||||
except paramiko.BadAuthenticationType:
|
except paramiko.BadAuthenticationType:
|
||||||
|
|
Loading…
Reference in New Issue