[erlang-questions] net_kernel:start without writing cookie file?

Lukas Larsson lukas@REDACTED
Fri Jul 13 15:33:07 CEST 2018


Hello,

On Tue, Jul 10, 2018 at 5:13 PM Roger Lipscombe <roger@REDACTED>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180713/20f3a7ea/attachment.htm>


More information about the erlang-questions mailing list