LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

kcadm.sh

Keycloak Admin CLI

TLDR

Log in to a Keycloak server (prompts for the password)
$ kcadm.sh config credentials --server [http://localhost:8080] --realm [master] --user [admin]
copy
Log in with a service account client secret
$ kcadm.sh config credentials --server [url] --realm [master] --client [client_id] --secret [secret]
copy
Create a realm
$ kcadm.sh create realms -s realm=[name] -s enabled=true
copy
Create a user and print its id
$ kcadm.sh create users -r [realm] -s username=[user] -s enabled=true -i
copy
Search users, showing selected fields
$ kcadm.sh get users -r [realm] -q username=[user] --fields id,username,email
copy
Update a user
$ kcadm.sh update users/[id] -r [realm] -s email=[email]
copy
Set a temporary password
$ kcadm.sh set-password -r [realm] --username [user] --new-password [pass] --temporary
copy
Assign a realm role to a user
$ kcadm.sh add-roles -r [realm] --uusername [user] --rolename [role]
copy
Create a client from a JSON file
$ kcadm.sh create clients -r [realm] -f [client.json]
copy

SYNOPSIS

kcadm.sh command [endpoint] [options]

DESCRIPTION

kcadm.sh is the Keycloak Admin CLI, shipped in the bin directory of the Keycloak server distribution (kcadm.bat on Windows). It is a thin client for the Keycloak Admin REST API: endpoints like realms, users, clients and groups map directly to REST paths.After config credentials stores an access token in the config file, subsequent commands reuse the session until it expires. Attributes are set with -s or supplied as JSON with -f.

PARAMETERS

--server URL

Server URL to log in to (config credentials).
--realm REALM
Realm to authenticate against.
--user USER, --password PASS
Login username and password; the password is prompted for or read from KC_CLI_PASSWORD if omitted.
--client ID, --secret SECRET
Client ID (default: admin-cli) and client secret for service account login.
-r, --target-realm REALM
Realm to operate on, if different from the login realm.
-s, --set NAME=VALUE
Set an attribute in the request body.
-f, --file FILE
Read the JSON body from a file, or stdin with -.
-q, --query NAME=VALUE
Add a query parameter to the request.
-F, --fields FILTER
Output only the given JSON fields.
--format FORMAT
Output format: json (default) or csv.
-o, --offset N, -l, --limit N
Paging for get requests.
-i, --id
Print only the id of a created resource.
--config FILE
Config file (default: ~/.keycloak/kcadm.config).
--no-config
Do not load or save a config file; authenticate per command.
--insecure
Disable TLS certificate validation.
-x
Print a full stack trace on error.

COMMANDS

config credentials

Authenticate and store a session in the config file.
config truststore
Configure a truststore for TLS connections.
create ENDPOINT
Create a resource (realms, users, clients, groups, roles, ...).
get ENDPOINT
Get one or more resources.
update ENDPOINT
Update a resource.
delete ENDPOINT
Delete a resource.
get-roles, add-roles, remove-roles
List, add or remove realm or client roles of a user, group or composite role.
set-password
Reset a user's password.
help [command]
Show help for a command.

CAVEATS

Requires Java and a running Keycloak server reachable over HTTP(S). Since Keycloak 17 (Quarkus), server URLs no longer include the /auth context path. Passing passwords on the command line exposes them in shell history; prefer the prompt or environment variables. The config file contains tokens and should be protected.

HISTORY

kcadm.sh is the official admin CLI for Keycloak, the open-source identity and access management solution started by Red Hat in 2014.

SEE ALSO

keycloak(1), curl(1), jq(1)

RESOURCES

Copied to clipboard
Kai