Erlang
Authentication Error
Remote Node
Erlang Cookie
Troubleshooting

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.cookie on Unix-based systems and in %HOMEDRIVE%%HOMEPATH%\.erlang.cookie on 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 400 on 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

  1. Mismatched Cookies: The most common cause of the authentication failure is that the two nodes trying to connect do not share the same cookie.
  2. 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.
  3. 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.
  1. Verifying the Cookie: Ensure that the cookies on both nodes are indeed the same. You can check the cookie by reading the .erlang.cookie file on each node.
  2. 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.
  3. Restarting Nodes: After synchronizing the cookies and setting appropriate file permissions, restart the nodes to ensure all changes take effect.

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:

bash
1# View the current cookie on node1
2cat $HOME/.erlang.cookie
3
4# Assume it outputs 'ABCDEF', which should then be set on node2
5echo 'ABCDEF' > $HOME/.erlang.cookie
6chmod 400 $HOME/.erlang.cookie  # Set proper permissions

Note: Replace ABCDEF with your actual cookie content.

Summary

The following table summarizes key points related to Erlang cookies and authentication issues:

AspectDetail
Purpose of CookieSecure communication between nodes by shared secret.
Default LocationUnix: $HOME/.erlang.cookie Windows: %HOMEPATH%\.erlang.cookie
Common IssueMismatched cookies leading to authentication failures.
ResolutionEnsure 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.


Course illustration
Course illustration

All Rights Reserved.