Changing the default username and password in RabbitMQ
First, access the command line on the server where RabbitMQ is installed in this case we used Homebrew to install our RabbitMQ server.
We can create a new user with a custom username and password using the rabbitmqctl command
. Replace new_username
and new_password
with your desired credentials.
rabbitmqctl add_user new_username new_password
After creating the new user, you want to set permissions for this user. You can set permissions to allow the user to access all vhosts (/ is the default vhost). The command below will give the user permissions to read, write, and configure queues on the default vhost. Adjust the permissions according to your needs.
using set_permissions -h
we see that we can supply a username and its permissions under
[--node <node>] [--longnames] [--quiet] set_permissions [--vhost <vhost>] <username> <conf> <write> <read>
rabbitmqctl set_permissions -p / new_username ".*" ".*" ".*"
Optionally, If the new user needs to have administrative access, you can set the user tag to administrator.
rabbitmqctl set_user_tags new_username administrator
By default, RabbitMQ creates a guest
user with the password with world's strongest password for simplicity guest
, but for security reasons, we will change the default user's password or delete the user. To change the password:
rabbitmqctl change_password guest new_guest_password
If you'd rather delete the guest user you can use this command below.
rabbitmqctl delete_user guest
After making all the changes needed, you should restart the RabbitMQ service to make sure all changes are applied and avoid conflicts. You can do this using your system's service management commands.
Since we're using Homebrew we will use the brew
command.
If you're on linux you can choose to sudo systemctl
commands
brew services restart rabbitmq
Finally, verify that the changes have been applied correctly. You can list users to see if your new user is created:
rabbitmqctl list_users
That's it, RabbitMQ should be all setup and secured!
Top comments (0)