Blog 2 mins reading time

Creating Users Using Keycloak Config CLI (Part 2/3)

Introduction

This guide details how to create users in Keycloak using Keycloak Config CLI. While Keycloak Config CLI is not meant for ongoing user management (better handled through the Admin Console or API), it is valuable for initializing users in development or automated deployments.

This guide builds upon the Keycloak Starter Guide. Ensure your Keycloak instance is running and configured as described in the previous guide.

Prerequisites

  • Running Keycloak Instance: See the Keycloak Starter Guide.
  • Keycloak Config CLI Installed: Ensure compatibility with Keycloak 25.0.1.
  • Administrative Access: You will need Keycloak admin credentials.

Step 1: Prepare the Configuration File

Create a file named my-keycloak-config.json in ./configs/:

Explanation of Fields:

  • “realm”: “realmWithUsers”: Must match the realm created earlier.
  • “enabled”: true: Enables the realm.
  • “users”: Array of user objects.
    • “username”: Unique username.
    • “email”: User’s email address.
    • “enabled”: Indicates if the account is active.
    • “firstName”/”lastName”: User’s personal details.
    • “attributes”: Custom user attributes.

Step 2: Apply the Configuration Using Keycloak Config CLI

Run this command:

Step 3: Verify the Users in Keycloak

  1. Log in to the Keycloak Admin Console.
  2. Navigate to Users under realmWithUsers.
  3. Confirm the user realmWithUsers exists and attributes are set correctly.
  4. You should see the myuser user listed. Click on the user to view its details and confirm that the attributes (email, first name, last name, locale) are set correctly.

Conclusion

Using Keycloak Config CLI for user management ensures consistency and efficiency, especially for automated deployments or initializing development environments. This method complements the declarative configuration approach for Keycloak.

 

Keen to explore how adorsys can guide your company through technology innovation? Reach out to us here, our team will be delighted to discuss tailored solutions for your organisation.

Written by Victoire Motouom, Fullstack Developer at adorsys Cameroon.