paramiko登陆主机代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了paramiko登陆主机代码相关的知识,希望对你有一定的参考价值。
def manual_auth(username, hostname): default_auth = ‘p‘ auth = 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.path.join(os.environ[‘HOME‘], ‘.ssh‘, ‘id_rsa‘) path = 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) elif auth == ‘d‘: default_path = os.path.join(os.environ[‘HOME‘], ‘.ssh‘, ‘id_dsa‘) path = 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) else: pw = getpass.getpass(‘Password for %[email protected]%s: ‘ % (username, hostname)) t.auth_password(username, pw)
本文出自 “kaman” 博客,请务必保留此出处http://3155037.blog.51cto.com/3145037/1956578
以上是关于paramiko登陆主机代码的主要内容,如果未能解决你的问题,请参考以下文章