I'm using the :client API to connect to an external node and use code there remotely, the thing though is that I'm using Dokku for deployment and it would be really nice if I could specify a ssh key at runtime.
Right now my code looks something like this:
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}'
I've tried something like setting the -rsh argument to be "-rsh ssh -i /path/to/id_rsh" but it seems to ignore this entirely, I'm not exactly sure how it's implemented and the Erlang docs for :client are a little hard to understand for me (I can see it uses :ssh underneath somewhere, and that can take a "user_dir" argument which can contain a key file, but I'm not sure how to set that from :client)
Any ideas?
The
-rshoption is intended to point to a different executable:These days people use
sshinstead ofrsh. (About 10 years ago the security team on a previous job requiredssheven when both machines are on the same isolated network.) Since the command line interface is compatible, just pointing to a new executable generally works once you have the keys set up properly. So it makes sense to use the-rshoption to point tosshinstead.It also seem logical that the argument could be used to pass other parameters to the
sshcommand as you attempted. However, the code assumes the string passed is the name of an executable in yourPATH. It usesos:find_executableto look for an executable andssh -i /path/to/id_rshprobably doesn't exist.However, you can take advantage of this feature to point to any executable including a shell script. For instance, you could write a
ssh-wrapperthat looks something like:Then use
-rsh /path/to/my/ssh-wrapperso that:slave.startuses your wrapper with the propersshoptions specified. I've found the wrapper technique also makes future maintenance easier as the connection logic stays in one place.Hat tip to this comment from Martin S.