无法使用Elixir连接到远程SSH服务器 [英] Not able to connect to a remote SSH server with Elixir

查看:120
本文介绍了无法使用Elixir连接到远程SSH服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用elixir连接到远程ssh服务器。

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

这是我在IEX中所做的:

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)>

首先,我必须说此错误消息根本没有帮助。我在Slack上获得了社区的大力支持。有人建议也启动inets应用程序。我确实尝试重新连接,但再次遇到相同的错误。

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 ?

[已修复]有多个问题。首先,必须在单引号之间提供服务器。然后,确保您的公钥不需要密码。如果是这样,则可以将其作为选项传递给connect函数。另外,也不必启动我启动的所有应用程序。 :ssh.start 是我唯一需要的一个。

[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.

推荐答案

如果我们查看 :ssh.connect / 3 我们看到 host 参数应该是一个字符串。由于是erlang函数的文档,因此字符串表示字符列表。单引号创建字符列表字符串,双引号创建utf-8编码的二进制字符串。改为这样调用函数::ssh.connect('my.server.co.uk',22,用户:'my_username')

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').

这篇关于无法使用Elixir连接到远程SSH服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆