python 如何配置dask连接到远程SSH服务器?

hm2xizp9  于 2023-05-27  发布在  Python
关注(0)|答案(1)|浏览(164)
from dask.distributed import Client, SSHCluster
cluster = SSHCluster(["localhost", "192.168.x.x"],
connect_options={"known_hosts": None, "username": "xxxx", "client_keys": "~/.ssh/dask" },
worker_options={"nthreads": 2},
scheduler_options={"port": 0, "dashboard_address": ":8797"})
client = Client(cluster)

获取错误

File "/home/naveen/anaconda3/envs/dask_env/lib/python3.8/site-packages/asyncssh/connection.py", line 218, in _connect
    await conn.wait_established()
  File "/home/naveen/anaconda3/envs/dask_env/lib/python3.8/site-packages/asyncssh/connection.py", line 2096, in wait_established
    await self._waiter
asyncssh.misc.PermissionDenied: Permission denied
vwkv1x7d

vwkv1x7d1#

client_keys必须是列表,指向私钥文件!
从文档:
用于通过基于主机的身份验证对此客户端进行身份验证的密钥列表。最简单的选择是传递要从中读取一个或多个私钥的文件的名称。
关于所有选项的更多信息可以在这里和这里找到。
下面是更新后的代码:

from dask.distributed import Client, SSHCluster

cluster = SSHCluster(
    ["localhost", "192.168.x.x"],
    connect_options={
        "known_hosts": None,
        "username": "xxxx",
        "client_keys": ["~/.ssh/dask/id_rsa"], # <--- HERE!
    },
)

client = Client(cluster)

在我看来,asyncssh.connect(以及作为SSHCluster的扩展)的用户体验和错误管理在这方面可以做得更好。

相关问题