diff options
author | Robey Pointer <robey@lag.net> | 2005-07-07 01:35:31 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-07-07 01:35:31 +0000 |
commit | ae18228d079224d71b20846b9c4bcc2a5537e135 (patch) | |
tree | 6433f221f2dca0242fe7cf413208067981998fca /demo.py | |
parent | e3ed1616d17f64ca394e7357b05eaf4c6b55ea1f (diff) |
[project @ Arch-1:robey@lag.net--2005-master-shake%paramiko--dev--1--patch-26]
new ssh agent support! from john rochester. added a bunch of docs to it, and changed demo.py to use an Agent if it finds a working key there.
Diffstat (limited to 'demo.py')
-rwxr-xr-x | demo.py | 79 |
1 files changed, 49 insertions, 30 deletions
@@ -50,6 +50,51 @@ def load_host_keys(): f.close() return keys +def agent_auth(username, t, event): + agent = paramiko.Agent() + agent_keys = agent.get_keys() + if len(agent_keys) > 0: + for key in agent_keys: + print 'Trying ssh-agent key %s' % paramiko.util.hexify(key.get_fingerprint()), + t.auth_publickey(username, key, event) + event.wait(10) + if t.is_authenticated(): + print '... success!' + return + print '... nope.' + +def manual_auth(username, hostname, event): + default_auth = 'p' + auth = raw_input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth) + if len(auth) == 0: + auth = default_auth + + if auth == 'r': + default_path = os.environ['HOME'] + '/.ssh/id_rsa' + path = raw_input('RSA key [%s]: ' % default_path) + if len(path) == 0: + path = default_path + try: + key = paramiko.RSAKey.from_private_key_file(path) + except paramiko.PasswordRequiredException: + password = getpass.getpass('RSA key password: ') + key = paramiko.RSAKey.from_private_key_file(path, password) + t.auth_publickey(username, key, event) + elif auth == 'd': + default_path = os.environ['HOME'] + '/.ssh/id_dsa' + path = raw_input('DSS key [%s]: ' % default_path) + if len(path) == 0: + path = default_path + try: + key = paramiko.DSSKey.from_private_key_file(path) + except paramiko.PasswordRequiredException: + password = getpass.getpass('DSS key password: ') + key = paramiko.DSSKey.from_private_key_file(path, password) + t.auth_publickey(username, key, event) + else: + pw = getpass.getpass('Password for %s@%s: ' % (username, hostname)) + t.auth_password(username, pw, event) + ##### main demo @@ -113,37 +158,11 @@ try: if len(username) == 0: username = default_username + agent_auth(username, t, event) + # ask for what kind of authentication to try - default_auth = 'p' - auth = raw_input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth) - if len(auth) == 0: - auth = default_auth - - if auth == 'r': - default_path = os.environ['HOME'] + '/.ssh/id_rsa' - path = raw_input('RSA key [%s]: ' % default_path) - if len(path) == 0: - path = default_path - try: - key = paramiko.RSAKey.from_private_key_file(path) - except paramiko.PasswordRequiredException: - password = getpass.getpass('RSA key password: ') - key = paramiko.RSAKey.from_private_key_file(path, password) - t.auth_publickey(username, key, event) - elif auth == 'd': - default_path = os.environ['HOME'] + '/.ssh/id_dsa' - path = raw_input('DSS key [%s]: ' % default_path) - if len(path) == 0: - path = default_path - try: - key = paramiko.DSSKey.from_private_key_file(path) - except paramiko.PasswordRequiredException: - password = getpass.getpass('DSS key password: ') - key = paramiko.DSSKey.from_private_key_file(path, password) - t.auth_publickey(username, key, event) - else: - pw = getpass.getpass('Password for %s@%s: ' % (username, hostname)) - t.auth_password(username, pw, event) + if not t.is_authenticated(): + manual_auth(username, hostname, event) event.wait(10) # print repr(t) |