الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

kcadm

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

المستوى
خدمة DevSecOps
المجموعة
الأسرار والهوية والتشفير
يحتاج root
لا
الحزمة
keycloak
يُسمّى أيضًا
kcadm.sh

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 8

الأكثر استخدامًا

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).

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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

انتبه

  • 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.

الملفات

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

نصائح للحفظ

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

رموز الخروج

0Success.
1Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man kcadm