Erlang 客户端设置 ssh 密钥

Erlang client set ssh key

我正在使用 :client API 连接到外部节点并在那里远程使用代码,不过我正在使用 Dokku 进行部署,这真的很棒如果我可以在运行时指定一个 ssh 密钥。

现在我的代码看起来像这样:

def start(host) do
  allow_boot to_char_list(host)
  {:ok, slave} = :slave.start(to_char_list(host), :slave, inet_loader_args)
  load_paths(slave)
  {:ok, slave}
end

inet_loader_args == ' -rsh ssh -loader inet -hosts #{master_node_ip} -setcookie #{:erlang.get_cookie}'

我试过将 -rsh 参数设置为 "-rsh ssh -i /path/to/id_rsh" 但它似乎完全忽略了这一点,我不确定它是如何实现的以及 :client 的 Erlang 文档对我来说有点难以理解(我可以看到它在某处使用 :ssh,并且可以采用 "user_dir" 参数,其中可以包含密钥文件,但我不确定如何设置它来自 :client)

有什么想法吗?

-rsh选项是intended to point to a different executable:

%% Alternative, if the master was started as
%% 'erl -sname xxx -rsh my_rsh...', then 'my_rsh' will be used instead
%% of 'rsh' (this is useful for systems where the rsh program is named
%% 'remsh').

如今人们使用 ssh 而不是 rsh。 (大约 10 年前,即使两台机器都在同一个隔离网络上,安全团队在以前的工作中也需要 ssh。)由于命令行界面是兼容的,只要指向一个新的可执行文件通常就可以按键设置正确。因此,使用 -rsh 选项指向 ssh 是有意义的。

在您尝试时,该参数可用于将其他参数传递给 ssh 命令似乎也合乎逻辑。但是,the code assumes the string passed is the name of an executable in your PATH. It uses os:find_executable 寻找可执行文件,ssh -i /path/to/id_rsh 可能不存在。

但是,您可以利用此功能指向 任何 可执行文件,包括 shell 脚本。例如,你可以写一个 ssh-wrapper 看起来像:

#!/usr/bin/env ksh
exec ssh -i /path/to/id_rsh $@

然后使用 -rsh /path/to/my/ssh-wrapper 以便 :slave.start 使用您的包装器并指定适当的 ssh 选项。我发现包装器技术还使将来的维护更容易,因为连接逻辑保留在一个地方。


致敬