TechBuzzPro

Failed to Create Cookie File RabbitMQ on Windows – Fix Guide

· 5 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you can resolve the “failed to create cookie file” error in RabbitMQ on Windows by granting the service proper file‑system permissions and, if necessary, creating the Erlang cookie manually.

What You'll Need

  • Administrator rights on the Windows machine
  • Access to a Command Prompt or PowerShell window running as Administrator
  • RabbitMQ installed (any recent version)
  • Erlang/OTP installed (matching the RabbitMQ version)
  • A text editor such as Notepad or Notepad++

Step-by-Step

  1. Confirm the user under which the RabbitMQ service runs. Open services.msc, locate RabbitMQ, right‑click > Properties > Log On. By default the service uses the Local System account, but some installations create a dedicated rabbitmq user. Note the account name because file permissions must include it.
  2. Locate the expected cookie path. RabbitMQ (through Erlang) looks for a file named .erlang.cookie in the home directory of the service account. For the Local System account the path resolves to %WINDIR%\System32\config\systemprofile\.erlang.cookie. For a custom user it is %HOMEDRIVE%%HOMEPATH%\.erlang.cookie. Open a Command Prompt and run:
    echo %USERPROFILE%\.erlang.cookie while logged in as the service account to verify the exact location.
  3. Check whether the cookie file already exists. In the resolved folder, run:
    dir /a .erlang.cookie.
    If the file is missing or its size is zero, RabbitMQ will attempt to create it and fail if it cannot write to that directory.
  4. Create a new cookie file manually. Generate a 20‑character string consisting of letters and numbers (uppercase/lowercase) – for example, AbC9dE4fGhIjK1LmN2Op. Open Notepad, paste the string, and save the file as .erlang.cookie in the folder identified in step 2. Ensure you select “All Files (*.*)” in the Save dialog to avoid adding a .txt extension.
  5. Set strict permissions on the cookie file. The Erlang runtime requires the cookie to be readable only by the owner. Run the following command, substituting ACCOUNT with the service account name from step 1:
    icacls "%USERPROFILE%\.erlang.cookie" /inheritance:r /grant:r ACCOUNT:F
    This removes inherited permissions and grants full control solely to the specified account. Verify with:
    icacls "%USERPROFILE%\.erlang.cookie".
  6. Mark the file as hidden and read‑only. Although not strictly required, hiding the file mirrors default Erlang behavior and reduces accidental edits. Execute:
    attrib +h +r "%USERPROFILE%\.erlang.cookie".
  7. Restart the RabbitMQ service. Return to services.msc, right‑click RabbitMQ, and choose Restart. Alternatively, use the command line:
    net stop rabbitmq followed by net start rabbitmq.
  8. Verify that the broker starts without the cookie error. Open a Command Prompt and run:
    rabbitmqctl status.
    If the service reports its status and no “failed to create cookie file” line appears in the output or in %APPDATA%\RabbitMQ\log\, the problem is resolved.

Common Mistakes

  • Saving the cookie file with a .txt extension. Always select “All Files” when saving to prevent the extra extension.
  • Granting permissions to the wrong user. The service account, not the interactive user, must own the file.
  • Placing the cookie in a folder that the service cannot access, such as a network share or a directory with restrictive Group Policy.
  • Using a cookie string that is shorter than 20 characters. Erlang expects at least 20 characters; shorter strings cause authentication failures.
  • Leaving the file readable by “Everyone”. Overly permissive ACLs trigger the same error because Erlang refuses insecure cookies.

Tips

  • Generate the cookie with a cryptographically strong random source. In PowerShell you can run:
    [System.Convert]::ToBase64String((1..20 | ForEach-Object {Get-Random -Maximum 256}))
  • If you manage multiple RabbitMQ nodes on the same host, copy the same cookie file to each node’s home directory to enable clustering.
  • After fixing the cookie, clear the RabbitMQ log directory (%APPDATA%\RabbitMQ\log\) to avoid confusion with stale error messages.
  • When using Windows containers, mount the cookie file into the container at C:\\Users\\ContainerUser\\.erlang.cookie and set the same restrictive ACLs inside the container.
  • Document the exact cookie value in a secure password manager; you will need it if you ever reinstall RabbitMQ or replace the host.

Troubleshooting

If the service still reports “failed to create cookie file” after following the steps above, try the following checks in order.

  1. Confirm the service actually uses the account you edited. Some installations run RabbitMQ under the Network Service account. Repeat step 1 and verify the correct home directory.
  2. Check for antivirus or endpoint protection interference. Real‑time scanners sometimes block creation of hidden files in system folders. Temporarily disable the scanner or add an exclusion for the cookie path, then restart the service.
  3. Verify that the folder itself is writable. Even with correct file ACLs, the parent directory may be read‑only. Run:
    icacls "%USERPROFILE%" and ensure the service account has F (full) rights on the directory.
  4. Look at the RabbitMQ log files for additional clues. Open %APPDATA%\RabbitMQ\log\rabbit@.log. Errors such as “EACCES” (permission denied) or “ENOENT” (no such file or directory) pinpoint the exact failure point.
  5. Ensure Erlang version compatibility. A mismatch between Erlang and RabbitMQ can cause the runtime to look for the cookie in a different location. Re‑install Erlang using the version recommended on the RabbitMQ download page.
  6. Reset the service’s configuration. Stop RabbitMQ, rename the entire %APPDATA%\RabbitMQ folder to RabbitMQ_backup, then start the service again. RabbitMQ will recreate its default configuration files, and you can copy the corrected .erlang.cookie back in.
  7. Re‑install RabbitMQ as a last resort. Uninstall via Programs & Features, delete any leftover .erlang.cookie files, reinstall, and immediately apply the permission steps before starting the service.

Frequently Asked Questions

Why does RabbitMQ need an Erlang cookie?

The cookie is a shared secret used by Erlang nodes to authenticate each other. Without matching cookies, nodes refuse to communicate, and the broker will not start.

Can I store the cookie in a different location?

Yes, you can set the RABBITMQ_ERLANG_COOKIE environment variable to point to a custom path, but the file must still meet the permission requirements.

Do I need to restart Windows after fixing the cookie?

No. Restarting the RabbitMQ service is sufficient. A full system reboot is only needed if you changed Group Policy settings that affect file permissions.

What length should the cookie be?

Erlang expects a string of at least 20 characters. Using 20‑30 random alphanumeric characters is standard practice.

Is it safe to make the cookie file readable by Administrators?

Administrators already have the ability to read any file on the system, but the cookie itself should not be world‑readable. Restricting the ACL to the service account satisfies Erlang’s security check.

My RabbitMQ node still shows “authentication failed” after fixing the cookie. What now?

Check that all nodes in a cluster share the exact same cookie value. If any node has a different cookie, clustering will fail and the broker may log authentication errors.