RabbitMQ
User Management
Messaging Queue
Server Administration
Technical Guide

How do I create or add a user to rabbitmq?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

RabbitMQ is a popular open-source message broker used to handle background jobs or asynchronous tasks by decoupling applications. Managing users in RabbitMQ is crucial for securing and limiting access to your message queues. This article explains how to create or add a user to RabbitMQ, along with setting permissions and understanding user roles.

Step 1: Installing RabbitMQ

Before adding users, ensure RabbitMQ is installed on your system. It is available for Windows, macOS, and Linux distributions. Installation guides can be found on the official RabbitMQ website.

Step 2: Accessing RabbitMQ Management Console

RabbitMQ provides a web-based management console, which can be accessed by installing the RabbitMQ management plugin. You can enable this plugin using the following command in the terminal:

bash
rabbitmq-plugins enable rabbitmq_management

After enabling the plugin, you can access the management console by navigating to http://localhost:15672/. The default username and password are guest.

Step 3: Creating a User

To add a user, you can use the RabbitMQ management console or the command-line interface. Here are the steps for both methods:

Using RabbitMQ Management Console:

  1. Log into the management console.
  2. Navigate to the "Admin" tab.
  3. In the "Users" section, click on "Add a user".
  4. Enter the username and password for the new user and click "Add user".

Using Command Line:

Open the terminal and run the following command:

bash
rabbitmqctl add_user <username> <password>

Replace <username> and <password> with the desired user credentials.

Step 4: Setting User Permissions

After creating a user, you need to set permissions to specify what the user can access and do within RabbitMQ. Permissions can be set for virtual hosts. By default, a virtual host named / exists in RabbitMQ.

To set permissions using the command line:

bash
rabbitmqctl set_permissions -p / <username> ".*" ".*" ".*"

This command grants the user full access to configure, write, and read operations within the default virtual host.

Step 5: Understanding User Roles

RabbitMQ supports various user roles, each allowing different levels of access and control:

  • Administrator: Full access to all management features.
  • Monitoring: Read-only access to monitoring features without configuration access.
  • Management: Limited management capabilities, suitable for application developers.
  • Policymaker: Can manage policies and parameters.

These roles can be applied from the management console or via the command line:

bash
rabbitmqctl set_user_tags <username> administrator

Step 6: Deleting or Updating Users

To update a user's password:

bash
rabbitmqctl change_password <username> <new_password>

To delete a user:

bash
rabbitmqctl delete_user <username>

Summary Table

Here is a summary of the key commands used:

ActionCommandDescription
Add Userrabbitmqctl add_user <username> <password>Adds a new user with specified credentials.
Set Permissionsrabbitmqctl set_permissions -p / <username> ".*" ".*" ".*"Sets permissions for a user on the default virtual host.
Set User Tagsrabbitmqctl set_user_tags <username> administratorAssigns roles to a user.
Change Passwordrabbitmqctl change_password <username> <new_password>Updates the user's password.
Delete Userrabbitmqctl delete_user <username>Deletes a user from RabbitMQ.

Additional Details

Ensure that the credentials and permissions you assign to users align with your organization's security practices. Consider organizing users and permissions according to their roles and responsibilities within your workflows.

Adding users in RabbitMQ effectively is a critical step in securing and customizing the message broker for your application needs. By following the guidelines provided here, you can maintain strong access control and operational integrity in your RabbitMQ installation.


Course illustration
Course illustration

All Rights Reserved.