Authentication failed (rejected by the remote node), please check the Erlang cookie
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When working with distributed Erlang systems, the synchronization of nodes is crucial for the seamless operation and communication between these nodes. One common issue encountered during the node communication setup is the "Authentication failed (rejected by the remote node), please check the Erlang cookie" error. Understanding what this error means and how to resolve it is essential for maintaining a robust distributed system.
Understanding Erlang Cookies
Erlang uses a mechanism known as "cookies" for its authentication purposes. This cookie is a simple alphanumeric string that acts as a shared secret between nodes. The primary function of this cookie is to ensure that only nodes with the identical cookie can communicate with each other, thereby providing a layer of security.
How Erlang Cookies Work
- Each Erlang node has a cookie stored in a text file.
- By default, this file is located at
$HOME/.erlang.cookieon Unix-based systems and in%HOMEDRIVE%%HOMEPATH%\.erlang.cookieon Windows.
- The cookie file should be readable only by the user and not exposed to others for security reasons (typically with file permissions set to
400on Unix). - When an Erlang node starts, it reads its cookie from this file.
- If a node tries to connect to another node, the connection will only succeed if both nodes have the exact same cookie.
Common Causes of Authentication Errors
- Mismatched Cookies: The most common cause of the authentication failure is that the two nodes trying to connect do not share the same cookie.
- File Permissions: Incorrect permissions on the cookie file might prevent a node from reading it, thus either using a default cookie or failing to start.
- Network Issues: Sometimes network configurations (like firewalls or wrong hostname configurations) can lead to miscommunications between nodes, though the error message might incorrectly suggest a cookie issue.
Resolving Cookie Mismatch Issues
- Verifying the Cookie: Ensure that the cookies on both nodes are indeed the same. You can check the cookie by reading the
.erlang.cookiefile on each node. - Synchronizing the Cookies: If the cookies differ, choose one cookie to be the standard and replace the cookie on other nodes to match this standard. Ensure the cookie files have the correct permissions after modification.
- Restarting Nodes: After synchronizing the cookies and setting appropriate file permissions, restart the nodes to ensure all changes take effect.
Example of Cookie Synchronization
Suppose you have two nodes, node1@host1 and node2@host2. After discovering a cookie mismatch, you decide to use the cookie from node1@host1 for both nodes:
Note: Replace ABCDEF with your actual cookie content.
Summary
The following table summarizes key points related to Erlang cookies and authentication issues:
| Aspect | Detail |
| Purpose of Cookie | Secure communication between nodes by shared secret. |
| Default Location | Unix: $HOME/.erlang.cookie
Windows: %HOMEPATH%\.erlang.cookie |
| Common Issue | Mismatched cookies leading to authentication failures. |
| Resolution | Ensure cookies match on all nodes and have correct permissions. |
Understanding and correctly managing your Erlang cookies is crucial for the security and integrity of your distributed Erlang applications. Always ensure that your system's nodes are properly synchronized to avoid unexpected authentication issues.

