net_kernel:start without writing cookie file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

net_kernel:start without writing cookie file?

Roger Lipscombe-2
When you start distribution with (e.g.) net_kernel:start([foo,
shortnames]), Erlang writes ~/.erlang.cookie as the current user, with
mode 600.

If you inadvertently use sudo to run your escript, it creates the
.erlang.cookie file owned by root. The next time you run your escript
without sudo (because it wasn't needed), Erlang dies with a
scary-looking error message.

Since our particular escript immediately calls erlang:set_cookie, it's
kinda pointless generating the cookie file.

Is there any way to disable this behaviour, so that people who
accidentally use 'sudo' don't get caught out?

Thanks,
Roger.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: net_kernel:start without writing cookie file?

Lukas Larsson-8
Hello,

On Tue, Jul 10, 2018 at 5:13 PM Roger Lipscombe <[hidden email]> wrote:
When you start distribution with (e.g.) net_kernel:start([foo,
shortnames]), Erlang writes ~/.erlang.cookie as the current user, with
mode 600.

If you inadvertently use sudo to run your escript, it creates the
.erlang.cookie file owned by root. The next time you run your escript
without sudo (because it wasn't needed), Erlang dies with a
scary-looking error message.

Since our particular escript immediately calls erlang:set_cookie, it's
kinda pointless generating the cookie file.

Is there any way to disable this behaviour, so that people who
accidentally use 'sudo' don't get caught out?

There is an undocumented option called "-nocookie" that seems to do what you want.

However if you want to use a documented way, doesn't it work to just set a static cookie in the escript and then change it later on? i.e.

%%! -setcookie nocookie
main(_) ->
  net_kernel:start([foo,shortnames]),
  erlang:set_cookie(node(),secret).

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions