I have a Phoenix app on a VPS. Instead of connecting to it via ssh first, is there a way to connect to it directly from my local computer?
For instance:
erl -remsh live@my_vps_ip_addr -sname debug@localhost_or_whatever_should_be_here
I have a Phoenix app on a VPS. Instead of connecting to it via ssh first, is there a way to connect to it directly from my local computer?
For instance:
erl -remsh live@my_vps_ip_addr -sname debug@localhost_or_whatever_should_be_here
Yes. If your application is started with a name
or sname
(and in case of an sname
both machines can connect to each other according to the sname
rules), both machines use the same cookie, the firewall is open for the port of EPMD and for the port that EPMD tells you your BEAM is running on.
On my server I run it as “bin/my_app foreground”. Should I add “sname” to it?
It’s been answered here before
Where does that answer my question
On my server I run it as “bin/my_app foreground”. Should I add “sname” to it?
?
But I can clarify it even more! You’re using distillery, meaning you ran mix release.init
to create your release. That created a file under rel/
called vm.args
which is read into the release. This is a great place to put options for the erlang runtime, like name
or sname
. If you look at that file, you’ll see that it already has a name
defined, unless you’ve changed it already!
## Name of the node
-name <%= release_name %>@127.0.0.1
You can change -name
to -sname
there, and only use the first part of the full name, if you prefer. For example replace it with
## Name of the node
-sname mycoolnode
The thread also clarifies that using sname
can be more difficult than name
, because you might not know what the second part of name@host
is. But your mileage might vary.
You want to connect to it using erl -remsh live@my_vps_ip_addr -sname debug@localhost_or_whatever_should_be_here
. Note that you wrote -sname debug@localhost_or_whatever
but -sname
only takes the name, not the host. Compare -sname debug
and -name debug@localhost
.
You really want something like erl -remsh mycoolnode@ip_address_or_dns_name -sname whatever
. And for this to work, the -name
part has to be what the remote node calls itself and it has to be accessible from your machine, eg the IP or DNS name. You can figure this out by running bin/my_app remote_console
on the remote machine, and then Node.self
.
You don’t want epmd’s/nodes ports available publicly. Unless it’s changed recently it is not really encrypted and even without the cookie someone can exhaust the atom space via crafting of packets and so forth.
how can it be “not really encrypted”? it can be either encrypted, or not.
Just putting it kindly that’s it is not encrypted. ^.^
Consequently that’s why I connect mine via SSH tunnels.