我正在使用paramiko连接到SSH服务器,并且我想临时添加host_keys。
我该怎么做?
import paramiko
client = paramiko.SSHClient()
client.load_system_host_keys()
#client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=str(host),username =str(user),password=str(pswd))
from paramiko import RSAKey
from paramiko.py3compat import decodebytes
client = SSHClient()
# known host key
know_host_key = "<KEY>"
keyObj = RSAKey(data=decodebytes(know_host_key.encode()))
# add to host keys
client.get_host_keys().add(hostname=HOST, keytype="ssh-rsa", key=keyObj)
# login to ssh hostname
client.connect(hostname=HOST, port=PORT, username=USER)...
来源:https://github.com/paramiko/paramiko/blob/2.6.0/tests/test_hostkeys.py#L75-L84