0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · Lesson

Distribution Security & Cookies

Secure communication between distributed Erlang nodes using magic cookies, node naming, and TLS distribution.

Distribution Security & Cookies is a free Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Erlang OTP: Distributed & Fault-Tolerant Systems Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Trust in a Cluster

Connected Erlang nodes fully trust each other: any node can run code on any other. That power makes securing distribution essential.

The Magic Cookie

Each node has a secret cookie. Two nodes can only connect if their cookies match. It is the basic authentication mechanism for clustering.

erlang:get_cookie().
% => 'SECRETCOOKIE'

Setting the Cookie

You can set the cookie at startup or at runtime. All nodes that should cluster must share the same value.

% at startup:
% erl -setcookie SECRET -name node1@host

erlang:set_cookie(node(), 'SECRET').

The .erlang.cookie File

If not set explicitly, the VM reads ~/.erlang.cookie. It must have restrictive permissions or the VM refuses to start.

% chmod 400 ~/.erlang.cookie

Short vs Long Names

Nodes use -sname (short hostname) or -name (fully qualified). Both nodes must use the same scheme to connect.

% erl -sname worker
% erl -name worker@10.0.0.5

Cookies Are Not Encryption

A matching cookie only authenticates the connection. By default, traffic between nodes is unencrypted. On untrusted networks you need TLS.

TLS Distribution

Erlang can tunnel all inter-node traffic over TLS using the inet_tls_dist module, configured via a proto_dist flag and a certificate file.

% erl -proto_dist inet_tls \
%     -ssl_dist_optfile ssl_dist.conf \
%     -name node1@host

The ssl_dist Config

The config file points to your certificate, key, and CA so nodes mutually authenticate and encrypt.

[{server, [{certfile, "node.pem"},
           {keyfile, "node.key"},
           {cacertfile, "ca.pem"}]},
 {client, [{cacertfile, "ca.pem"}]}].

Restricting epmd Exposure

The Erlang Port Mapper Daemon (epmd) registers node ports. Never expose epmd or distribution ports to the public internet; firewall them or use a VPN.

Hidden Nodes

A node started with -hidden connects without joining the global mesh, useful for tools that should not be part of the cluster's full-trust topology.

% erl -hidden -name monitor@host

Security Checklist

For safe distribution:

  • Use a strong, unique cookie
  • Protect the cookie file (chmod 400)
  • Enable TLS on untrusted networks
  • Firewall epmd and distribution ports

Quick Check

Test your distribution security knowledge.

Recap

You learned to secure distributed Erlang.

  • Matching cookies authenticate nodes
  • Protect the .erlang.cookie file
  • Use TLS distribution for encryption
  • Firewall epmd and distribution ports

Frequently asked questions

Is the “Distribution Security & Cookies” lesson free?

Yes — the full text of “Distribution Security & Cookies” is free to read here on the web, and the Erlang OTP: Distributed & Fault-Tolerant Systems Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Erlang OTP: Distributed & Fault-Tolerant Systems Programming course, upgrade to CoddyKit PRO.

What will I learn in “Distribution Security & Cookies”?

Secure communication between distributed Erlang nodes using magic cookies, node naming, and TLS distribution. You practise Erlang OTP: Distributed & Fault-Tolerant Systems Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

No prior experience is required. Erlang OTP: Distributed & Fault-Tolerant Systems Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Distribution Security & Cookies” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson?

Yes. Every Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Node Communication & Setup
  2. Remote Procedure Calls (RPC)
  3. Global Process Registration
  4. Distribution Security & Cookies
← Back to Erlang OTP: Distributed & Fault-Tolerant Systems Programming