Not able to connect to a remote SSH server with Elixir

给你一囗甜甜゛ 提交于 2019-12-23 13:22:50

问题


I have been trying for a while to connect to a remote ssh server with elixir.

This is what I do in IEX:

[Macintosh] elixir/logglycious (master|…)> iex                                                                            15-07-20 0:11
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :application.start(:crypto)
{:error, {:already_started, :crypto}}
iex(2)> :application.start(:public_key)
{:error, {:not_started, :asn1}}
iex(3)> :application.start(:asn1)
:ok
iex(4)> :application.start(:public_key)
:ok
iex(5)> :application.start(:ssl)
:ok
iex(6)> :application.start(:ssh)
:ok
iex(7)> :ssh.connect("my.server.co.uk", 22, [ { :user, 'my_username' } ])
{:error, {:options, {:socket_options, [:inet]}}}
iex(8)>

First of all, I must say this error message is not helping at all. I received great support from the community on Slack though. Someone suggested to start the inets application too. I did and retried to connect but I got the same error again.

What am I doing wrong ? More importantly, how can I find the solution to such a problem next time ?

[FIXED] There were multiple issues. First the server must be provided between single quotes. Then make sure that your public key does not require a passphrase. If it does, it can be passed as an option to the connect function. Also, it is not necessary to start all the applications I started. :ssh.startis the only one I needed.


回答1:


If we look at the documentation for :ssh.connect/3 we see that the host argument should be a string. Since it's documentation for an erlang function the string means a charlist. Single quotes creates charlist strings, double quotes create utf-8 encoded binary strings. Call the function like this instead: :ssh.connect('my.server.co.uk', 22, user: 'my_username').



来源:https://stackoverflow.com/questions/31507015/not-able-to-connect-to-a-remote-ssh-server-with-elixir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!