To connect to your existing node:
- ssh to your server.
- Start a new Erlang node + shell session with a new name but the same cookie as the node you want to contact (
erl -name some_name -cookie some_cookie
).
- From the new Erlang shell press
^G
(that is, CTRL+G
) to open the terminal command interface.
- Enter the command string
r [email protected]
to connect to the other node remotely.
- Press
j
to list the current jobs. The new shell spawned on the node you are trying to contact will be listed.
- Enter
c [the remote shell's job number]
to connect to the new shell on the node you want to use.
Here is my first node, called '[email protected]'
:
ceverett@changa:~$ erl -name foo -cookie bar
Erlang/OTP 20 [RELEASE CANDIDATE 2] [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.0 (abort with ^G)
([email protected])1>
Here is my second node, called '[email protected]'
that I will use to start a remote shell connection to the other. Note that I have started this erl session with the same cookie (the option -cookie bar
) as above:
ceverett@changa:~$ erl -name baz -cookie bar
Erlang/OTP 20 [RELEASE CANDIDATE 2] [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.0 (abort with ^G)
([email protected])1>
User switch command
--> ?
c [nn] - connect to job
i [nn] - interrupt job
k [nn] - kill job
j - list all jobs
s [shell] - start local shell
r [node [shell]] - start remote shell
q - quit erlang
? | h - this message
--> r '[email protected]'
--> j
1 {shell,start,[init]}
2* {'[email protected]',shell,start,[]}
--> c 2
Eshell V9.0 (abort with ^G)
([email protected])1>
Notice how my prompt changed at the bottom? That's all there is to it.
This works between any Erlang nodes that are connected in a cluster, and with EPMD running using long node names remote nodes will try to connect to one another if they are able to see each other on the network. In this case both nodes are running on the same host, but as long as hosts can see each other on the network it works the same way.