Skip to content

Keycloak user import JSON from CSV

Turn a CSV of users into JSON for a Keycloak partial import or realm import, with groups, realm roles, attributes and required actions.

Runs in your browser. Nothing you paste is sent to us.

CSV

Columns: username, email, firstName, lastName, enabled, emailVerified, password, temporary, groups, realmRoles. Other columns become attributes. Made-up people are filled in.

For several groups or roles in one cell.

Output

Users JSON

3 users attributes: department

JSON
{
  "users": [
    {
      "username": "alice",
      "email": "[email protected]",
      "firstName": "Alice",
      "lastName": "Sample",
      "enabled": true,
      "emailVerified": false,
      "requiredActions": [
        "UPDATE_PASSWORD"
      ],
      "groups": [
        "/staff"
      ],
      "realmRoles": [
        "user",
        "editor"
      ],
      "attributes": {
        "department": [
          "Sales"
        ]
      }
    },
    {
      "username": "bob",
      "email": "[email protected]",
      "firstName": "Bob",
      "lastName": "Sample",
      "enabled": true,
      "emailVerified": false,
      "requiredActions": [
        "UPDATE_PASSWORD"
      ],
      "groups": [
        "/staff/support"
      ],
      "realmRoles": [
        "user"
      ],
      "attributes": {
        "department": [
          "Support"
        ]
      }
    },
    {
      "username": "carol",
      "email": "[email protected]",
      "firstName": "Carol",
      "lastName": "Sample",
      "enabled": true,
      "emailVerified": false,
      "requiredActions": [
        "UPDATE_PASSWORD"
      ],
      "realmRoles": [
        "user"
      ]
    }
  ]
}
In the admin console: Realm settings, Action, Partial import. Choose what to do when a user already exists. Groups and roles must already exist (or be in the same import); groups are written as paths such as /staff/support.
Keycloak keeps only attributes its user profile knows about, unless the realm allows unmanaged attributes. Add the columns to the user profile first.

How to use it

  1. Paste the CSV with a header row.
  2. Choose what happens to users without a password.
  3. Pick partial import or a realm import file.
  4. Save the JSON and import it.

What to know

Keycloak imports users from JSON, not CSV. The tool maps the usual columns (username, email, names, enabled, groups and realm roles) and turns other columns into user attributes.

Users without a password can be asked to set one at first sign-in, or you can send them a reset link afterwards. Plain passwords in a file are hashed on import, but the file still holds them.

Groups and roles must exist before the import, or come in the same file. Groups are written as paths, such as /staff/support.

Getting users into Keycloak

Sooner or later every Keycloak project has to load users that already exist somewhere else: a spreadsheet from HR, an export from an old application, a list of customers from a previous login system. Keycloak has no CSV import. It reads users as JSON, in the same shape it uses in realm exports.

This tool turns a CSV with a header row into that JSON. You can load it with the admin console’s partial import or put it in a realm import file, without writing a script.

The ways Keycloak can load users

MethodGood forNotes
Partial import in the admin consoleAdding users to a realm that already existsAsks what to do when a user exists: fail, skip or overwrite.
Realm import with --import-realmCreating a new realm with its usersSkips a realm that already exists.
Admin REST APIOngoing sync from another systemOne request per user; needs a script.
User federation (LDAP, Active Directory)Users who stay in a directoryNo import file; users are read from the directory.

For a one-time load of a few hundred or a few thousand users, partial import is usually the simplest. For users who should keep living in a directory, federation is the better fit, and the LDAP filter checker helps choose which of them Keycloak sees.

The user JSON Keycloak reads

Each user is an object with a username and optional fields. Groups are written as paths and realm roles by name.

One made-up user, as the tool writes it
{
  "users": [
    {
      "username": "alice",
      "firstName": "Alice",
      "lastName": "Sample",
      "enabled": true,
      "emailVerified": false,
      "requiredActions": ["UPDATE_PASSWORD"],
      "groups": ["/staff"],
      "realmRoles": ["user", "editor"],
      "attributes": { "department": ["Sales"] }
    }
  ]
}

Attribute values are always lists of strings, even when there is only one value. Group paths start with a slash and name every parent group, such as /staff/support.

What this tool does

It reads CSV separated by commas or semicolons, with quoted fields as spreadsheets write them. The header names the columns, in any order and in any letter case.

ColumnBecomes
usernameusername, in lower case
emailemail; also the username when there is no username column
firstName, lastNamefirstName, lastName
enabledenabled (true, yes, 1 or y); true when empty
emailVerifiedemailVerified; otherwise the option you choose
password, temporaryA password credential; temporary unless the column says otherwise
groupsGroup paths, several separated by the cell separator
realmRolesRealm role names, several separated by the cell separator
Any other columnA user attribute, if you keep that option on

It warns about rows with no username or email, rows with a different number of fields than the header, duplicate usernames and email addresses that do not look valid. It can add the Update Password required action to every user without a password, and it writes either a partial import file or a realm import file.

Preparing the CSV

Spreadsheet programs offer several CSV formats. Choose CSV with UTF-8 encoding, so names with accents or other scripts arrive intact. Some locales write semicolons instead of commas; the tool detects that from the header row. Remove empty rows at the end, and avoid merged cells or formulas in the export.

If one cell needs several groups or roles, separate them with a character that never appears in the names, such as a semicolon or a pipe, and set the same character in the tool.

What it does not do

It does not create groups or roles. They must exist in the realm, or be part of the same import, before users can join them. It does not set client roles, identity provider links or credentials other than plain passwords. It does not hash passwords; for that, see the next section. It does not send anything to Keycloak: you save the file and import it yourself.

Passwords

You have three choices, from safest to riskiest.

No password, with Update Password

Leave the password column out and keep the Update Password option on. Then send each user a link with the admin API’s execute-actions email, or let them use Forgot password. Nobody ever sees a password. This needs the realm’s email settings to work.

Existing hashes

If the old system stored PBKDF2 hashes, you can import them as credentials and users keep their passwords. The password hash generator shows the credential format Keycloak expects. Other algorithms, such as bcrypt, need a custom provider in Keycloak or a password reset.

Plain passwords in the CSV

The tool turns a password column into a credential with a plain value, marked temporary unless you say otherwise. Keycloak hashes it on import, but the CSV and the JSON hold it in plain text until you delete them. Use this only for test realms or one-time passwords people must change.

How to use it

  1. Create the groups and realm roles your users need, if they do not exist yet.
  2. Export the users from the old system as CSV with a header row. Rename columns to the names above, or keep extra columns as attributes.
  3. Paste the CSV. A few made-up users are filled in to show the format.
  4. Choose the cell separator for groups and roles, whether users must set a password, and whether emails are verified.
  5. Read the warnings and fix the CSV until none are left.
  6. Pick partial import or realm import, and save the file.
  7. In the admin console, open Realm settings, Action, Partial import, choose the file and choose what happens to existing users.

Real-world uses

Moving from another login system

When an application moves its sign-in to Keycloak, its users move too. Export them with their groups, import them with Update Password, and send reset links. If the old system used PBKDF2, import the hashes instead so nobody has to reset.

Seeding a test or staging realm

A CSV of test users with known roles makes repeatable test setups. Keep it in the repository and rebuild the realm from it whenever you need a fresh copy.

Onboarding a customer or a team

Business customers often send a spreadsheet of the people who need access. Convert it, check the warnings, import, and email the users their set-password link.

Common problems

ProblemLikely causeFix
Users imported without their groupsThe groups did not exist, or the path is wrongCreate the groups first and use full paths.
Attributes missing after importThe user profile does not know themAdd them to the realm’s user profile, or allow unmanaged attributes.
Import stops at a userThe user exists and the policy is failChoose skip or overwrite in the partial import.
Two users with one emailThe realm does not allow duplicate emailsClean the CSV; the warnings show duplicate usernames.
Reset emails never arriveNo SMTP settings in the realmSet up email under Realm settings, Email.

Security and privacy

The CSV and the JSON hold personal data, and maybe passwords. This page converts them in your browser and sends nothing to us. Keep the files out of shared folders and tickets, and delete them after the import. Prefer no passwords at all, so the files hold nothing that grants access.

Best practices

  • Import into a staging realm first and sign in as a few of the users.
  • Use lower-case usernames; the tool lowercases them for you.
  • Mark emails verified only when the old system really verified them.
  • Declare custom attributes in the user profile before the import.
  • Load large numbers of users in batches, so one bad row does not hide the rest.
  • For a move to managed hosting, plan users together with the rest of the realm; our migration page describes how that works.
Questions

Frequently asked questions

Can Keycloak import users from a CSV file?

Not directly. Keycloak reads users as JSON. Convert the CSV with this tool, then use Partial import in the admin console or a realm import file.

How do I bulk import users into Keycloak?

Build a JSON file with a `users` list and load it with Realm settings, Action, Partial import. For a new realm, put the users in the realm import file and start Keycloak with `--import-realm`.

How do I import users with their passwords?

If the old system used PBKDF2, import the hashes as credentials with `secretData` and `credentialData`. Otherwise import users without passwords and have them set one with Update Password or a reset email.

How do I add imported users to groups?

List group paths in the user’s `groups` field, such as `/staff/support`. The groups must exist before the import or be in the same file.

What happens if a user already exists during partial import?

You choose: fail the import, skip the user, or overwrite the existing user with the one from the file.

Why are my custom attributes missing after the import?

Keycloak keeps attributes its user profile knows about, unless the realm allows unmanaged attributes. Add the attributes to the user profile, then import again.

How do I make imported users set their own password?

Add the `UPDATE_PASSWORD` required action to each user. Then send them a link with the admin API’s execute-actions email, or let them use Forgot password.

Is my CSV uploaded?

No. The conversion runs in your browser. The file still holds personal data, so delete it once the users are imported.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.