RabbitMQ Error Guide: 'Authentication failed (rejected by the remote node), please check the Erlang cookie' — Fix Cookie Mismatch
Fix the RabbitMQ Erlang cookie mismatch that blocks rabbitmqctl and cluster joins: locate the .erlang.cookie file, align its value and permissions across nodes, and restart cleanly.
- #rabbitmq
- #messaging
- #troubleshooting
- #errors
Stuck on this RabbitMQ error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
RabbitMQ nodes and CLI tools authenticate to each other using a shared secret called the Erlang cookie. When that secret does not match, any attempt to talk to the node over Erlang distribution — running rabbitmqctl, joining a cluster, or a node connecting to a peer — is rejected. The most common wording is:
Error: unable to perform an operation on node 'rabbit@node1'. Please see diagnostics information and suggestions below.
Most common reasons for this are:
* Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
* CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
* Target node is not running
...
* Authentication failed (rejected by the remote node), please check the Erlang cookie
In the node’s own log the peer-side of the same failure appears as a rejected distribution handshake:
** Connection attempt from node 'rabbitmqcli-1234-rabbit@node1' rejected. Invalid challenge reply. **
Both messages describe one condition: the cookie presented does not equal the cookie the target expects.
Symptoms
rabbitmqctl status,list_queues, or any CLI command fails immediately with “Authentication failed (rejected by the remote node), please check the Erlang cookie”.- A new node cannot join the cluster:
rabbitmqctl join_cluster rabbit@node1fails with the same authentication error even though the host is reachable and pingable. - The server log shows
Connection attempt from node ... rejected. Invalid challenge reply.each time you run a CLI command or a peer tries to connect. - The broker itself may be running fine and serving AMQP clients on 5672, while all management via
rabbitmqctlis blocked — a strong sign the problem is the cookie, not the broker. - After a fresh package reinstall, container rebuild, or restore from backup, a previously-working node suddenly can’t be administered.
Common Root Causes
- Cookies differ between nodes. Each node generated its own random cookie at first boot; you never copied one shared value across the cluster.
- CLI cookie differs from the server cookie. The user running
rabbitmqctl(often your shell user or root) reads a cookie from their home directory that doesn’t match therabbitmqservice user’s cookie. - Wrong file permissions or ownership. The cookie file must be owned by the running user and mode
400/600; Erlang refuses to use a cookie file that is group/world readable and may fall back to a different value. - A stray newline or whitespace. Editing the cookie in a text editor added a trailing newline, so the byte content differs even though the visible characters match.
- Container image baked one cookie, volume mounted another. In Docker/Kubernetes the image’s
.erlang.cookieand a mounted secret disagree, orRABBITMQ_ERLANG_COOKIEwas set for one node but not another. - Reinstall regenerated the cookie. Removing and reinstalling the package (or recreating the container) produced a new random cookie that no longer matches the surviving cluster members.
Diagnostic Workflow
All commands below are read-only until the resolution section. Run them on the affected node.
First, confirm the node is actually reachable and running, to rule out a network/hostname problem masquerading as a cookie error:
rabbitmq-diagnostics ping
rabbitmq-diagnostics status
If ping fails to connect at all, it’s a reachability issue; if it connects but reports an authentication rejection, it’s the cookie.
Find where each cookie lives and compare the raw values. The service user’s cookie and the CLI user’s cookie must be byte-identical:
# Cookie the RabbitMQ service user reads (Debian/RPM package default)
sudo cat /var/lib/rabbitmq/.erlang.cookie
# Cookie the current shell user reads when running rabbitmqctl
cat "$HOME/.erlang.cookie"
Compare them without printing the secret to the terminal or logs:
sudo sha256sum /var/lib/rabbitmq/.erlang.cookie "$HOME/.erlang.cookie"
Matching hashes mean the cookies agree; differing hashes are the smoking gun. Repeat the same sha256sum on every cluster node and confirm they all match.
Check ownership and permissions — Erlang ignores a cookie file that is too permissive:
sudo ls -l /var/lib/rabbitmq/.erlang.cookie
The file should be owned by rabbitmq:rabbitmq (or your service user) with mode -r-------- (400) or -rw------- (600).
Confirm which cookie the running VM actually loaded and inspect the distribution failures in the log:
rabbitmq-diagnostics erlang_cookie_sources
sudo tail -n 50 /var/log/rabbitmq/rabbit@$(hostname -s).log | grep -i "challenge\|cookie\|rejected"
Example Root Cause Analysis
A team added a third node, rabbit@node3, to an existing two-node cluster and the join failed with “Authentication failed (rejected by the remote node), please check the Erlang cookie” — even though ping to rabbit@node1 succeeded and DNS resolved cleanly.
Running sudo sha256sum /var/lib/rabbitmq/.erlang.cookie on all three nodes showed node1 and node2 with an identical hash, but node3 with a different one. Node3 had been provisioned from a plain package install, which generates a fresh random cookie on first boot; nobody had copied the cluster’s shared cookie onto it. The reachability was fine — the handshake was being rejected purely because node3 presented the wrong secret, which the node1 log confirmed with repeated Invalid challenge reply entries.
The fix was to stop node3, replace its /var/lib/rabbitmq/.erlang.cookie with the exact byte content from node1 (400 permissions, owned by rabbitmq), reset its Mnesia state, and rejoin. After aligning the cookie, rabbitmqctl join_cluster rabbit@node1 succeeded on the first try and the Invalid challenge reply messages stopped. The lesson: on a cookie error, compare the hashes before touching anything else — it distinguishes a secret mismatch from the reachability problems that produce a superficially similar message.
Prevention Best Practices
- Provision the cookie, don’t let it be generated. Distribute one known cookie value to
/var/lib/rabbitmq/.erlang.cookievia your configuration management, secret manager, or Kubernetes Secret before the node first starts. - Set permissions explicitly. Own the file as the service user and set mode
400so Erlang trusts it and so the secret isn’t world-readable. - Write the raw value with no trailing newline (
printf '%s' "$COOKIE" > .erlang.cookie), since an extra byte makes an otherwise-correct cookie mismatch. - Use a consistent source across environments. In containers, mount the same secret into every node or set
RABBITMQ_ERLANG_COOKIEuniformly; don’t bake one into the image and override it unevenly. - Verify after any reinstall or restore. A package reinstall or container rebuild can regenerate the cookie — re-check the hashes across nodes as part of the runbook.
- Keep CLI and service cookies aligned. If you run
rabbitmqctlas a non-service user, ensure that user’s$HOME/.erlang.cookiematches, or run the CLI as the service user.
Quick Command Reference
# Is it reachability or authentication?
rabbitmq-diagnostics ping
# Compare cookies without printing the secret
sudo sha256sum /var/lib/rabbitmq/.erlang.cookie "$HOME/.erlang.cookie"
# Check ownership/permissions (want rabbitmq:rabbitmq, mode 400)
sudo ls -l /var/lib/rabbitmq/.erlang.cookie
# Which cookie did the VM load?
rabbitmq-diagnostics erlang_cookie_sources
# Look at rejected distribution handshakes
sudo grep -i "challenge\|rejected" /var/log/rabbitmq/rabbit@$(hostname -s).log
# Fix: align the cookie, then restart (stop service first)
sudo systemctl stop rabbitmq-server
sudo install -o rabbitmq -g rabbitmq -m 400 /path/to/shared.cookie /var/lib/rabbitmq/.erlang.cookie
sudo systemctl start rabbitmq-server
Conclusion
The Erlang cookie error is one of the easiest RabbitMQ failures to fix once you stop treating it as a broker problem. The broker is usually healthy and serving AMQP clients; what’s broken is the shared secret that CLI tools and peer nodes use to authenticate over Erlang distribution. The decisive diagnostic is comparing the cookie hashes across the service user, the CLI user, and every cluster node — matching hashes clear the cookie of suspicion and point you at reachability instead, while a mismatch tells you exactly where to align the value.
Resolve it by making one cookie authoritative, writing it with the right permissions and no stray bytes, restarting the affected node, and re-verifying the hashes. Then prevent recurrence by provisioning the cookie explicitly through configuration management or a secret rather than letting each install generate its own. For more cluster and node-identity issues, see the RabbitMQ guides.
Fixed it? Get 500 RabbitMQ & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.