python - 无法通过 AsyncSSH 连接,错误主机密钥不受信任
问题描述
当我运行此脚本时,我收到SSH connection failed: Host key is not trusted
错误,但即使连接到此主机以获取密钥,仍会收到此错误。
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(请参阅指定已知主机)–(可选)将用于验证 SSH 握手期间提供的服务器主机密钥的密钥列表。如果未指定,则将在文件 .ssh/known_hosts 中查找密钥。如果明确设置为 None,服务器主机密钥验证将被禁用。
推荐阅读
- python - 为什么 Sentry 推荐的 Django 日志记录配置使来自 django.db.backends 的日志记录静音?
- javascript - js如何在屏幕上移动动画
- php - Mysql将数据插入double类型
- python - 我想知道如何在 Python 中计算两种 numpy 数组类型的相似度(数值精度)
- jquery - 通过 bgcolor 属性选择元素
- spring-boot - 类路径资源 [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class] 无法打开,因为它不存在
- youtube - 某些 YouTube URL 的 Wagtail 视频嵌入失败,但其他的则不然
- sql-server - SQL Server在转换为CHAR时截断浮点字段中的整数值
- css - 为什么具有 z-index 值的元素不能覆盖其子元素?
- performance - CosmosDb SQL 查询中是否存在单个 UPPER 会强制对分区进行完整的集合扫描?