-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_paramiko.py
46 lines (36 loc) · 1.3 KB
/
test_paramiko.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import paramiko
import logging
import sys
logging.basicConfig()
logging.getLogger("paramiko").setLevel(logging.DEBUG)
def connect(host, user, port=22, password=None, allow_agent=True):
# print("{0}\n{1}\n{0}".format("#"*80, cluster))
print("#1 initializing")
ssh = paramiko.SSHClient()
# Automatically load host if unknown
# https://stackoverflow.com/questions/52632693/force-password-authentication-ignore-keys-in-ssh-folder-in-paramiko-in-python
print("#2 missing host key policy")
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("#3 connect")
ssh.connect(
host,
username=user,
password=password,
port=port,
allow_agent=allow_agent,
timeout=10,
)
print("#4 get auth_method")
print(ssh.get_transport().auth_handler.auth_method)
if __name__ == "__main__":
args = sys.argv
for key in paramiko.agent.Agent().get_keys():
if not hasattr(key, "public_blob"):
key.public_blob = None
print(key.public_blob)
connect(host=args[1],
user=args[2],
port=int(args[3]),
password=None if args[4] == "None" else args[4],
allow_agent=False if args[5] == "False" else True,
)