gpt4 book ai didi

python - 无法通过 AsyncSSH 连接,错误主机 key 不受信任

转载 作者:行者123 更新时间:2023-12-05 02:42:53 25 4
gpt4 key购买 nike

当我运行这个脚本时,我收到 SSH connection failed: Host key is not trusted 错误,但即使连接到此主机以获取 key ,也会收到此错误。

import asyncio, asyncssh, sys

async def run_client():
async with asyncssh.connect('172.18.17.9', username="user", password="admin", port=9321) as conn:
result = await conn.run('display version', check=True)
print(result.stdout, end='')

try:
asyncio.get_event_loop().run_until_complete(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))

最佳答案

尝试将 known_hosts=None 参数添加到连接方法。

asyncssh.connect('172.18.17.9', username="user", password="admin", port=9321, known_hosts=None)

来自此处的 asyncssh 文档: https://asyncssh.readthedocs.io/en/latest/api.html#asyncssh.SSHClientConnectionOptions

known_hosts (see Specifying known hosts) – (optional) The list of keyswhich will be used to validate the server host key presented duringthe SSH handshake. If this is not specified, the keys will be lookedup in the file .ssh/known_hosts. If this is explicitly set to None,server host key validation will be disabled.

关于python - 无法通过 AsyncSSH 连接,错误主机 key 不受信任,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67222941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com