Recovering lost admin access to Keycloak

Regain control of a Keycloak server when the admin password is lost or MFA has locked every administrator out, without leaving an unmanaged backdoor behind.

On this page

Recovering lost Keycloak admin access without opening a backdoor

Recovering access when every administrator is locked out means using Keycloak's own administrative paths to restore a controlled admin identity, then removing the blocking credential, not editing the database or creating hidden accounts. The situation is common: an admin loses a password, a single MFA device is lost, or the only enrolled administrator leaves, and the admin console refuses every change. The recovery goal is a documented, auditable way back in that leaves no residual access once the work is finished.

The bootstrap admin exists for first-time setup of a new server. Keycloak creates it from the initial admin environment settings and is meant to be used once, after which a permanent administrator in a named realm should take over. If the bootstrap account was deleted or never created, or its credentials are gone, the team must choose between a supported recovery path and rebuilding. Common approaches share three traits: they run with access to the server or its configuration, they use kcadm or an equivalent admin client authenticated outside the locked console, and they require an change record and a follow-up review of every account that was created or altered. Confirm in your own environment which of these paths your version supports before an incident, and rehearse one in a non-production copy.

Bring in outside help when recovery touches the production database, when no one on the team can show who holds server access, or when the lockout may be a symptom of compromise rather than forgetfulness. Ask a partner to confirm the exact steps for your release, to review the temporary admins and sessions created during recovery, and to document what the audit log can and cannot show. A quote should cover investigation time, rehearsal in a copy of your environment, and the post-incident review, because those drive effort more than the single command that removes a credential.

Recovery options and when each fits

This table compares four ways to regain control of a Keycloak administration console: the bootstrap admin, a service account, a direct kcadm change, and a temporary admin created at startup. Read each row against your own situation, especially who can reach the server or database and what trail the action leaves. The main takeaway is that the fastest option is often the one that leaves the weakest audit record, so choose the least privileged path that still works.

OptionWhat it changes and who can run itAudit trail and when it is the wrong choice
Bootstrap admin userCreates or resets the initial admin account when the server starts with bootstrap credentials. Anyone who can set startup environment variables or restart the server can use it.Trail depends on your log configuration; confirm that startup and login events are captured. Wrong choice if the account was already used for daily work or if the server is not under your control.
Service account with client credentialsUses a confidential client with a service account granted admin roles in the master realm. Requires someone who can already read or update that client's secret.Token and admin events show the client ID, not a person. Wrong choice if the client secret is stored where many people can read it, or if the client holds broader roles than the recovery needs.
Direct kcadm credential or required-action resetUses the admin CLI against the server to reset a password or clear a required action such as an MFA enrollment on a named admin user. Requires administrative API access and credentials for the CLI.Changes appear as admin events if events are enabled; confirm this before you start. Wrong choice if you cannot prove who holds CLI credentials, or if the lockout is caused by a realm setting that the reset will not fix.
Temporary admin created at startupRedeploys Keycloak with a temporary admin account and removes it afterwards. Requires control of the deployment manifest, container image or service configuration and a restart.Deployment history and startup logs record the change, but the account is shared by whoever runs the deployment. Wrong choice for routine lockouts because a restart affects every user and the account must be removed afterwards.
Restore from database backupReturns the admin records to an earlier state from a backup taken before the lockout. Requires database administrators and a planned maintenance window.Database backup logs show the restore, but changes made after the backup point are lost. Wrong choice when user, client or realm changes since the backup would be overwritten.

Steps to regain access and verify the fix

This sequence restores at least one working administrator, removes the credential or required action that blocked the others, and confirms every admin can sign in again without leaving a temporary account behind.

  1. Confirm the lockout scope and freeze changes

    The platform owner and the identity administrator agree on which accounts are locked out, which realm and clients are affected, and whether public sign-in is still working. Stop other configuration changes, pause automated jobs that touch realms or clients, and record the current state, including the Keycloak version and the last change made. Done means a written note lists the locked accounts, the blocking symptom (lost password, failing MFA, or a required action), and the named person who will carry out each later step.

  2. Confirm server and database access controls

    Before any recovery action, confirm who can reach the Keycloak host, its container runtime or Operator-managed pods, and the production database. Recovery steps usually run on the server or in a pod, so access should go through your normal privileged path with logging turned on. Check that the admin console and Administration REST API are not reachable from public hostnames for this work. Done means the operator running the recovery can name the host or pod they will use, and the access log entry for that session exists.

  3. Create or use a bootstrap admin

    Use the supported bootstrap path for your release to create a temporary administrator in the master realm, typically by setting bootstrap admin environment variables or running the documented bootstrap command, then restart or run the command as the release documents. Confirm the exact variable names, command syntax and whether the account is created only when no admin exists, because these have changed across releases. Done means a new administrator account exists in the master realm and you can see it in the user list through the database or admin API. Record the account name and its creation time for later cleanup.

  4. Authenticate kcadm against the master realm

    Run the Keycloak admin CLI, kcadm, from the same release as the server, point it at the server URL, and log in to the master realm with the bootstrap administrator. Confirm the server URL, the realm flag and the login syntax in the documentation for your version before running it. Done means kcadm returns an authenticated session, and a read-only query such as listing realms succeeds. If it fails, check TLS trust, the hostname that the server advertises, and whether the account has the master realm admin role.

  5. Remove or reset the blocking credential

    Using kcadm, identify the locked administrator, then either reset the password, delete the blocking OTP or WebAuthn credential, or clear the required action that is forcing a step the user cannot complete. Change one item at a time and record each change with its command and time. Confirm the exact subcommands and flags for your release, because credential and required action commands are version-sensitive. Done means a read query shows the target user with the credential or required action removed or reset, and the change appears in the admin events or audit log.

  6. Sign in through the admin console

    Open the admin console from the protected admin hostname or path, sign in as the restored administrator, and complete any enrollment the account now requires, such as setting a new password or registering a new second factor. Keep the enrollment within the approved policy for administrators. Done means the administrator reaches the admin console home page for the target realm and can open a user record and a client record without error.

  7. Verify each administrator can sign in

    Ask every locked administrator to sign in once and complete their own credential setup, then confirm each one can reach the realms they manage. Check the admin events for successful logins and the login failure records that the release stores. Done means each administrator has a recorded successful sign-in, and the list of administrators matches the approved list from step one. Any account that still fails goes back to step five with its own findings.

  8. Remove temporary administrators and close the record

    Delete the bootstrap administrator and any other temporary accounts created for recovery, and confirm no unused admin roles or service accounts remain. Review the remaining admin list against your access policy, then restore the paused jobs and changes. Confirm the exact deletion commands for your release before running them. Done means the admin list contains only approved accounts, the bootstrap account no longer exists, and the recovery record with commands, times and operators is filed with the change ticket.

Decision path for choosing a recovery route

The path starts with a locked-out administrator and first asks whether anyone has shell access to the Keycloak host or container. If a working admin remains, the fix is an in-console change. If the blocker is a password, a kcadm credential reset or a bootstrap admin is the next route. If the blocker is an MFA credential, remove that credential with kcadm before anything else. Every route ends in an audit step that confirms the change, records who made it, and removes temporary admins. Escalation to a recovery partner is the last branch, used when no route is available.

Routes for regaining admin access, ending in a mandatory audit step.

Security controls for an emergency admin path

An emergency admin path is useful only if it is harder to misuse than the problem it solves. The controls below cover who holds emergency access, how it is used and recorded, and how the admin endpoints are kept away from public traffic. Each one should be decided before the first lockout, not during it.

Emergency accounts left enabled

A bootstrap or recovery admin that stays active after the incident gives an attacker a permanent, high-privilege login. Decide who may enable the account, under what ticket or incident number, and who disables it again. Check after every recovery that the account is disabled and that its password or credential has been rotated. Confirm the disabled state with a query against the admin realm, not only with the console. Keep the account out of day-to-day use so its activity is easy to spot.

Keycloak docs

Shared admin credentials

When several engineers know one administrator password, no log can say who made a change. Give each administrator a named account and reserve the emergency path for a small number of named custodians. Store the emergency credential in a sealed vault with two-person access, and record each retrieval. If the team cannot name who used the credential, treat the account as compromised and rotate it.

Recovery actions with no audit trail

Recovery steps such as clearing an OTP credential or resetting a password are high-impact changes that must leave evidence. Enable admin event logging in the realm and forward it to a system the admin team cannot edit. Before running a recovery command, write down the target user, the change and the reason. Compare the events with that record after the work is finished. Confirm which admin events your version captures and where they are stored.

Temporary admins never removed

Temporary administrators are often created for a migration or outage and then forgotten. Give each one an owner, an expiry date and a removal step in the change record. Review the realm role mappings on a fixed schedule and remove any admin role that no open ticket explains. Treat a temporary admin with MFA disabled as a higher risk than one that still requires a second factor.

MFA reset by a single person

A single administrator who can clear another user's second factor can also take over that user's account. Require a second person to approve any MFA or credential reset for an administrator account, and record both approvals. Where the platform allows it, restrict credential management to a separate admin role that few people hold. Test the approval step during a drill so it does not fail under pressure.

Exposed admin endpoints

The admin console and Administration REST API should not share a public hostname or context path with the login pages. Keycloak's production guidance calls for a separate hostname or path for admin traffic, reached only from management networks or through a restricted reverse proxy. Verify from outside your network that the admin paths do not resolve or return a login page, and that the emergency path is reachable only from the admin network. Confirm the exact proxy rules with your platform team and test them after every ingress change.

Production guide

Cleaning up temporary admins after recovery

In a small deployment with a single realm, the temporary admin is usually a user in the master realm, and the cleanup is short but easy to skip. Once permanent administrators are signed in with working credentials and MFA, the temporary account should stop being able to log in and then be removed. Keep the change small and recorded so the next person can see what was done and why.

  • Confirm a permanent admin first: Sign in with a named administrator account, check its MFA enrollment and confirm it can open the admin console before touching the temporary account.
  • Disable before deleting: Set the temporary user to disabled and confirm the login fails, then delete it after a short observation period agreed with your team.
  • Rotate any secret it touched: If the temporary admin was used with a client secret, rotate that secret and update the systems that read it.
  • Review role mappings: Check the permanent admin's realm role and client role mappings in the master realm so no privilege depends on the temporary account.
  • Record the change: Note the account name, the time, the person who approved the removal and the ticket or incident reference.

Before closing the task, confirm that no automation or scheduled job still authenticates with the removed account.

Limits to confirm in your environment

Recovery steps depend on how your Keycloak was installed, upgraded and configured. The cards below list the points to confirm in your own environment before an outage, so the recovery path you rehearse is the one that works on your release.

Bootstrap and kcadm behavior for your release

The exact kcadm commands and bootstrap admin behavior depend on the Keycloak release you run. The current release is 26.8.1, but many estates run older 26.x builds. Confirm the syntax, the required authentication flags and whether the bootstrap admin mechanism still applies on your version by testing against a non-production copy. Record the working commands in your runbook with the release number beside them.

Keycloak docs

Effect of manual schema migration

Keycloak migrates its database schema automatically at startup by default, but larger deployments may apply the SQL manually. If your team runs manual migration, a recovery that touches realm or user data must not assume the schema is at the expected version. Confirm which migration mode you use, and whether a restored backup needs the same migration applied before admin changes work.

Upgrading guide

Operator reconciliation of manual changes

If you deploy with the Keycloak Operator, check whether it reconciles manual changes back to the custom resource definitions. A direct edit made during recovery, such as re-enabling an admin account or changing a credential policy, may be reverted on the next reconcile and lock you out again. Confirm the reconcile behavior in your operator version and make recovery changes in the same source of truth you use for normal operations.

Operator installation

MFA recovery codes and passkeys for admins

Before an incident, confirm whether administrator accounts have recovery codes or passkeys enrolled, and whether your realm policy requires a second factor for the master realm. If an OTP device is lost and no recovery path exists, the only route back may be a command-line change to the credential. Document which admins hold recovery material, where it is stored, and who may authorize its use.

Whether brokered login was the only admin route

If administrators sign in only through an external identity provider, a broker outage or a changed upstream configuration can remove every login path to the admin console. Confirm whether a local admin account exists and whether it can still authenticate with its own credentials. Test that the local path works, and keep its credentials in a secured vault rather than in personal password managers.

Cleanup of temporary admin accounts

Recovery often creates a temporary administrator that must be removed afterward. Confirm which accounts, roles and client scopes were added during the incident, and that each one is disabled or deleted once access is restored. Check the admin event or logging records that your configuration retains, so the cleanup can be verified against what was actually created.

Questions teams ask before recovering Keycloak admin access

How much recovery effort depends on server and database access?

The effort depends mostly on whether you can reach the Keycloak host, its command line and the database behind it. With shell access to a Keycloak node and a working admin path through the kcadm command line tool, a locked-out administrator can often recover by removing a blocking credential or creating a temporary admin. Without shell access, you may need to involve the team that runs the cluster, the database administrators and the change process that governs production. Database access matters too, because some fixes are easier to verify with a direct look at the user and credential tables, and any direct write should be reviewed and backed up first. Ask your team which of these three paths they can reach today, before an incident forces the question.

Do we need an outside partner to recover Keycloak admin access?

Not always. Many recoveries are short procedures that an engineer who already runs Keycloak can carry out from a runbook. An outside partner becomes useful when the lockout is tangled with a broken cluster, an unknown configuration, missing backups or a change freeze that requires documented approval. To scope outside help, you will need to provide the Keycloak version, how it is deployed (containers, Kubernetes, virtual machines or the Operator), the database type, the realm and client layout, who holds the remaining administrator accounts, and the recent change history. You should also name a person who can approve production changes during the work, since recovery usually touches live authentication.

Can our own team recover Keycloak admin access in-house?

Yes, if the team has prepared for it. The core tasks are a bootstrap administrator that exists outside the normal login path, documented steps for kcadm sign-in and credential removal, and a tested way to reach the admin API without the console. Teams without that preparation can still recover, but they should work from a copy of the environment first, record each command and confirm the result with a second person. Practice the procedure in a non-production realm or a lab instance before you need it. Keep the recovery credentials in a sealed store with access logged, so the fix does not create a new way in for an attacker.

How long does recovery take depending on the blocker?

Duration depends on the blocker, the access you have and the approvals needed. A forgotten password for a bootstrap administrator usually takes less time than a multi-factor lockout where every administrator lost the second factor, because the second case can require reviewing realm settings, identity provider configuration and the audit trail before any credential is removed. A broken cluster or unreachable database adds infrastructure work before the admin fix can start. Ask any provider or internal team to break the work into diagnosis, access restoration, the fix itself, verification and cleanup, and to state which steps depend on your change approvals. No fixed duration is given here, because none has been confirmed for your environment.

What changes after we recover Keycloak admin access?

Recovery should end with a tighter setup, not the same gap reopened. Expect to remove temporary administrators, rotate the credentials used during the work, confirm that each remaining administrator can sign in with at least one supported second factor, and record which recovery paths now exist. Review the bootstrap administrator and any service accounts used for automation, and limit their roles to what they need. Also check whether the lockout exposed a gap in realm policies, such as no backup administrator or no tested recovery runbook. The Keycloak server administration guide documents how administrator roles, OTP policies, recovery codes and passkeys are set, which helps when you decide what the permanent setup should look like.

Does recovering admin access leave evidence for auditors?

It can, if you plan for it before the work starts. Keycloak records administrative events when event logging is enabled, and your infrastructure logs may capture shell sessions, database changes and changes to secrets. Auditors will usually ask for a written record of who authorized the recovery, what was changed, when, by whom and how it was verified, along with proof that temporary access was removed. Preparing these records is not the same as an audit result. DeployOpen prepares systems, controls and evidence for compliance assessments but does not issue audit reports or attestations; independent auditors make that determination. Ask your auditor which evidence they expect for privileged access changes.

What to change after access is restored

The most important change after recovery is making sure the next lockout does not require the same emergency. Add at least one second administrator with a named, individually owned account in the master realm, and give that person the same tested path into the admin console before anyone needs it. A single bootstrap or temporary admin is a single point of failure, and the recovery steps in this topic only help if someone other than the person who was locked out can carry them out. Confirm which admin roles the second account holds, and confirm that its MFA enrollment does not depend on the device or phone of the first administrator.

Next, write down the emergency path and name its owner. The runbook should state who may invoke it, where the break-glass credentials are stored and who approves their use, how the use is logged, and when the temporary admin is removed. Review the MFA recovery paths for every administrator account, including recovery codes and any reset process that an operator can run, and decide whether those codes are issued and stored in a way your security team accepts. Review realm admin roles at the same time, because accounts that were granted broad access during recovery are often never narrowed again. The Keycloak server administration guide describes the admin roles, realm-level permissions and OTP and recovery code settings, and it is the source for the exact configuration, so treat this section as the decision list and that guide as the reference.

Finally, rehearse the whole procedure in a non-production environment that matches your production realm configuration, including the MFA policy and the admin roles. A rehearsal shows whether the runbook still matches the Keycloak version you run, since admin console layouts and CLI behavior can change between releases. Record how long each step took and who needed to be involved, then schedule the rehearsal again after each upgrade or change to admin authentication. Confirm with your own team how often rehearsal is required by your internal policy, and keep the results with the runbook so that auditors or incident reviewers can see the procedure was tested.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.