[Erlang危機](4.3)SSH守護進程,erlangssh
原創文章,轉載請註明出處:伺服器非業餘研究http://blog.csdn.net/erlib 作者Sunface聯絡郵箱:cto@188.com
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實現,它即可以做伺服器,也可以做用戶端。SSH的部分實現是erlang中遠程shell的示範demo。
為了讓它工作起來,你通常需要把你的SSH在遠程伺服器上部署好。但因為我們只是做實驗,就可以像下面這樣子做:
-----------------------------------------------------------------------------------
$ 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.
在上面我先設定了幾個選項,指定了存放host檔案的系統目錄(system_dir),指定了包含SSH設定檔的使用者目錄(user_dir).其實還有大量其它選項:設定特定的密碼,自訂公開金鑰(public keys)等等3。
To connect to the daemon, any SSH client will do:
任意的的SSH用戶端都可以通過以下代碼串連上這個守護進程(daemon):
-----------------------------------------------------------------------------------
$ ssh -p 8989 ferd@127.0.0.1
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
這樣你就不用在本地安裝Erlang也能使用其它節點的Erlang了。直接斷開SSH會話後(關閉終端)就可以安全離開。但千萬不能輸出q()或init:stop()之類終結遠程shell的命令4。(牢記直接要串連遠程節點,就不能調用q()或init:stop() - Sunface)
If you have trouble connecting, you can add the -oLogLevel=DEBUG option to ssh to get debug output.
如果無法串連SSH成功,可以為SSH加一個選項 -oLogLevel=DEBUG, 然後輸出debug資訊。
[3] Complete instructions with all options to get this set up are available athttp://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節點的方法都不要用!