Stuff Goes Bad:Erlang In Anger

SSH Daemon

Erlang/OTP comes shipped with an SSH implementation that can both act as a server and a client. Part of it is a demo application providing a remote shell working in Erlang.
To get this to work, you usually need to have your keys to have access to SSH stuff remotely in place already, but for quick test purposes, you can get things working by doing:

 Erlang/OTP附带了一个SSH实现,它即可以做服务器,也可以做客户端。它的一部分可作为演示application,可以看作是提供一个远程使用Erlang工作的shell。
 为了让它工作起来,你通常需要把你的SSH keys在远程服务器上部署好。但为了快速体验到这个功能,你也可以像下面这样子做:

-----------------------------------------------------------------------------------
$ mkdir /tmp/ssh
$ ssh-keygen -t rsa -f /tmp/ssh/ssh_host_rsa_key
$ ssh-keygen -t rsa1 -f /tmp/ssh/ssh_host_key
$ ssh-keygen -t dsa -f /tmp/ssh/ssh_host_dsa_key
$ erl
1> application:ensure_all_started(ssh).
{ok,[crypto,asn1,public_key,ssh]}
2> ssh:daemon(8989, [{system_dir, "/tmp/ssh"},
2> {user_dir, "/home/ferd/.ssh"}]).
{ok,<0.52.0>}
-----------------------------------------------------------------------------------

I’ve only set a few options here, namely system_dir, which is where the host files are, and user_dir, which contains SSH configuration files. There are plenty of other options available to allow for specific passwords, customize handling of public keys, and so on 3.
To connect to the daemon, any SSH client will do:

 在上面我只设置了几个选项,指定存放host文件的系统目录(system_dir),指定包含SSH配置文件的用户文件.其实还有大量可用其它选项:允许特定的密码,自定义的公钥(public keys)等等3
 任意的的SSH客户端都可以连接上这个精灵进程(daemon):

-----------------------------------------------------------------------------------
$ ssh -p 8989 [email protected]
Eshell Vx.x.x (abort with ^G)
1>
-----------------------------------------------------------------------------------
And with this you can interact with an Erlang installation without having it installed on the current machine. Just disconnecting from the SSH session (closing the terminal) will be enough to leave. Do not run functions such as q() or init:stop() , which will terminate the remote host. 4
If you have trouble connecting, you can add the -oLogLevel=DEBUG option to ssh to get debug output.

 这样你就可以不需要本地安装Erlang,也使用远程的Erlang了。直接断开SSH session(关闭终端)就可以安全离开。但千万不能输出q()或init:stop()之类终结远程shell的命令4
  如果你连接遇到问题,你可以加一个选项 -oLogLevel=DEBUG 让把debug信息输出。

[3] Complete instructions with all options to get this set up are available at http://www.erlang.org/doc/man/ssh.html#daemon-3.
[4] This is true for all methods of interacting with a remote Erlang node.

[注3]:关于所有选项的说明见:http://www.erlang.org/doc/man/ssh.html#daemon-3.
[注4]:这种命令对所有连接远程Erlang节点的方法都不要用!