Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

kcadm

The admin CLI of Keycloak, the open-source identity server: realms, users, groups, roles and OIDC/SAML clients from scripts.

Niveau
DevSecOps-service
Groep
Secrets
Root nodig
Nee
Pakket
keycloak
Ook
kcadm.sh

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Keycloak gives single sign-on (OIDC, OAuth 2.0, SAML) for apps, Grafana, Argo CD, Kubernetes dashboards and more, with MFA, user federation (LDAP/AD) and identity brokering (Entra ID, GitHub). kcadm.sh (in bin/ of the Keycloak folder or container) calls the admin REST API, so you can create realms, clients and users in automation.

A realm is a separate space of users and apps; a client is an app that uses Keycloak to log users in.

Zo schrijf je het

kcadm.sh COMMAND ENDPOINT [-r REALM] [-s key=value ...] [ARGS]

Belangrijkste delen

Commands

config credentials
Log in to the server.
create ENDPOINT
Create (realms, users, clients, roles).
get ENDPOINT
Read.
update ENDPOINT
Change.
delete ENDPOINT
Delete.
set-password
Set a user password.
add-roles / remove-roles
Give or take roles.
get-roles
Show roles.

Opties 8

Meest gebruikt

Flags

--server URL
Keycloak address (config credentials).
--realm master --user admin
Where and who to log in as.
-r REALM
Target realm.
-s key=value
Set a field.
-f FILE
JSON body from a file.
-q key=value
Query filter (get).
--fields a, b
Only some fields.
-i
Print only the new ID (create).

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Run Keycloak in a container for the lab

    podman run -d --name keycloak -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=ChangeMe! quay.io/keycloak/keycloak:26.0 start-dev
  2. 2Log in with the CLI

    podman exec -it keycloak bash
    /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin
  3. 3Create a realm with brute-force protection

    kcadm.sh create realms -s realm=lab -s enabled=true -s bruteForceProtected=true -s 'passwordPolicy="length(12) and notUsername"'
  4. 4Create a user and set a password

    kcadm.sh create users -r lab -s username=hosam -s enabled=true -s email=hosam.test@example.com
    kcadm.sh set-password -r lab --username hosam --new-password 'Temp-Pass-2026!' --temporary
  5. 5Create an OIDC client for Grafana

    kcadm.sh create clients -r lab -s clientId=grafana -s protocol=openid-connect -s publicClient=false -s 'redirectUris=["https://grafana.lab.local/login/generic_oauth"]' -i
  6. 6Read the client secret

    kcadm.sh get clients -r lab -q clientId=grafana --fields id
    kcadm.sh get clients/3f2a91c0-1d2e-4f5a-9b8c-7d6e5f4a3b2c/client-secret -r lab
  7. 7Create a group and a role, give the role

    kcadm.sh create groups -r lab -s name=sre
    kcadm.sh create roles -r lab -s name=admin
    kcadm.sh add-roles -r lab --uusername hosam --rolename admin
  8. 8Require OTP for all users

    kcadm.sh update authentication/required-actions/CONFIGURE_TOTP -r lab -s defaultAction=true
  9. 9List users

    kcadm.sh get users -r lab --fields username,enabled,email
  10. 10Check the OIDC discovery document

    curl -s http://localhost:8080/realms/lab/.well-known/openid-configuration | jq '.issuer, .token_endpoint'
  11. 11Export a realm for Git (in the container)

    /opt/keycloak/bin/kc.sh export --dir /tmp/export --realm lab

Let op

  • start-dev is only for labs (HTTP, no cache cluster). Production needs start with TLS and a database.
  • Change the bootstrap admin, enable MFA for admins, and do not expose /admin publicly.

Bestanden

~/.keycloak/kcadm.config
CLI login token.

Tips om te onthouden

  • Manage realms as code with the Keycloak Terraform provider or keycloak-config-cli.

Exitcodes

0Success.
1Error.