Apparently this thread gets quite a few hits, presumably from Google.
So I'm going to answer it in more detail even though there's a decent amount of information
available in the docs linked to in this thread (after all, what self respecting developer reads docs, right?)
Here are some lines produced by rabbitmqctl (or rabbitmq-plugins) that you may be staring at right now:
So what the hell do they mean? Let's find out.
it then proceeded to successfully open a TCP connection on that port. However, even though TCP connection
succeeded, rabbitmqctl could not authenticate with the target node and therefore cannot proceed
with executing the command.
What can be the reason? rabbitmqctl lists a few very common ones (sadly, in the order that puts
the most common reason at number 2):
> * suggestion: hostname mismatch?
RabbitMQ node name has a hostname part. if CLI contact the node using a different name, authentication
will fail. This is a relatively rare scenario.
This is the meat and potatoes part. As [2] explains in a dedicated sections,
nodes and CLI tools authenticate using a shared secret — called the Erlang cookie — to each other.
The cookie value must match exactly or authentication will fail.
Where is the secret value retrieved from?
By default it is read from a local file, $HOME/.erlang.cookie (on Windows it is more involved, see [4]), as a single string
of up to 255 characters in size.
It is therefore important to make sure that all server nodes have that file (provisioning tools such as Chef, Puppet, Ansible or Docker
can help with that) as well as all machines *and all users* that will run CLI tools.
Since this is a shared secret, the file must have the permissions of 0600 (accessible only to the user).
When CLI tools are executed via `sudo`, their effective user changes (typically to `root`), and thus changes the value of the cookie file path, $HOME/.erlang.cookie.
Almost always the failure described above is due to a non-existent or misplaced cookie file, or an incorrect (mismatching) value in it. More often
than not it's on the CLI tool end.
Starting with 3.7.0, rabbitmqctl and other CLI tools support setting the cookie in two more ways:
* via the --erlang-cookie [value] CLI flag which accepts a string
* via the `RABBITMQ_ERLANG_COOKIE` environment variable