{
  "manifest_version": "1",
  "slug": "keycloak",
  "title": "Keycloak",
  "headline": "Self-host Keycloak",
  "description": "Self-host Keycloak with Docker and PostgreSQL on an exe.dev VM: public login pages, a private admin console, OIDC sign-in for Grafana, and backups.",
  "category": "security",
  "tags": [
    "keycloak",
    "single sign-on",
    "sso",
    "oidc",
    "saml",
    "identity provider",
    "docker compose",
    "postgresql",
    "authentik",
    "auth0 alternative"
  ],
  "url": "https://exe.dev/deploy/keycloak",
  "markdown_url": "https://exe.dev/deploy/keycloak.md",
  "upstream": {
    "website": "https://www.keycloak.org/",
    "source": "https://github.com/keycloak/keycloak",
    "docs": "https://www.keycloak.org/documentation",
    "license": "Apache-2.0"
  },
  "example_vm_name": "my-keycloak",
  "time": "20 minutes",
  "stack": [
    {
      "name": "Keycloak 26.8",
      "detail": "The official image in production mode, with a 2 GB memory limit",
      "port": 8180
    },
    {
      "name": "PostgreSQL 18",
      "detail": "Keycloak's database, in the same Compose stack",
      "data": "~/keycloak/postgres"
    },
    {
      "name": "nginx",
      "detail": "Port 8000 serves only realm logins; port 8080 serves the admin console",
      "port": 8000
    },
    {
      "name": "Nightly backup",
      "detail": "A systemd timer; a database dump plus the settings, kept two weeks",
      "data": "~/keycloak/backups"
    }
  ],
  "access": [
    {
      "url": "https://my-keycloak.exe.xyz/",
      "who": "public",
      "what": "Login pages, the account page and the OIDC and SAML endpoints of your realms, once you open it"
    },
    {
      "url": "https://my-keycloak.exe.xyz:8080/",
      "who": "private",
      "what": "The admin console, the admin API and the master realm, behind exe.dev login"
    }
  ],
  "delivers": [
    "Keycloak in production mode on PostgreSQL, with its URLs set for exe.dev's HTTPS proxy.",
    "A permanent admin account in place of the temporary one, with its password in a file only you can read.",
    "An apps realm for your users, with brute-force protection on.",
    "A public port that serves only realm logins, and refuses the admin console and master realm.",
    "Nightly database backups, with one restored into a scratch database to check it.",
    "Everything starts again after a reboot."
  ],
  "deployable": true,
  "deploy": {
    "new_vm_url": "https://exe.dev/new?prompt=Set%20up%20Keycloak%20on%20this%20VM%20by%20following%20the%20exe.dev%20recipe%20at%20https%3A%2F%2Fexe.dev%2Fdeploy%2Fkeycloak.md%3Fvia%3Ddeploy%20from%20top%20to%20bottom.%0A%0AThe%20recipe%27s%20example%20VM%20name%20is%20my-keycloak.%20This%20VM%27s%20name%20is%20the%20output%20of%20%60hostname%60%3A%20use%20it%20wherever%20the%20recipe%20writes%20my-keycloak.%20Skip%20the%20step%20that%20creates%20the%20VM%3B%20you%20are%20on%20it.%0A%0AYou%20are%20done%20when%20all%20of%20these%20are%20true.%20Check%20each%20one%20yourself%3A%0A-%20Keycloak%20in%20production%20mode%20on%20PostgreSQL%2C%20with%20its%20URLs%20set%20for%20exe.dev%27s%20HTTPS%20proxy.%0A-%20A%20permanent%20admin%20account%20in%20place%20of%20the%20temporary%20one%2C%20with%20its%20password%20in%20a%20file%20only%20you%20can%20read.%0A-%20An%20apps%20realm%20for%20your%20users%2C%20with%20brute-force%20protection%20on.%0A-%20A%20public%20port%20that%20serves%20only%20realm%20logins%2C%20and%20refuses%20the%20admin%20console%20and%20master%20realm.%0A-%20Nightly%20database%20backups%2C%20with%20one%20restored%20into%20a%20scratch%20database%20to%20check%20it.%0A-%20Everything%20starts%20again%20after%20a%20reboot.%0A%0ARead%20the%20whole%20recipe%2C%20including%20the%20closed%20details.%20For%20initial%20setup%2C%0Afollow%20%22Install%20by%20hand%22%20first%2C%20skipping%20VM%20creation%20and%20SSH%3A%20Docker%2C%0Athe%20settings%2C%20starting%20Keycloak%2C%20replacing%20the%20temporary%20admin%2C%20the%20apps%0Arealm%2C%20nginx%2C%20the%20backup%20timer%2C%20and%20the%20backup%20test.%20The%20walkthrough%20at%0Athe%20top%20is%20for%20the%20owner%20afterwards.%0AWork%20as%20exedev%20in%20~%2Fkeycloak.%20Never%20overwrite%20an%20existing%20.env.%20Don%27t%0Acreate%20users%20or%20clients%2C%20set%20up%20SMTP%20or%20connect%20apps%20unless%20the%20owner%0Aasks.%20Don%27t%20run%20Restore%20or%20Update.%20You%20can%27t%20make%20the%20VM%20public%20from%0Athe%20VM%3B%20leave%20that%20to%20the%20owner%2C%20and%20don%27t%20ask%20them%20to%20until%20you%27re%20done.%0AVerify%20docker.service%20and%20nginx%20are%20enabled%2C%20both%20containers%20use%0Aunless-stopped%20and%20are%20healthy%2C%20the%20apps%20realm%27s%20discovery%20document%20on%0Alocalhost%3A8000%20names%20https%3A%2F%2F%3Cvm%3E.exe.xyz%2Frealms%2Fapps%20as%20its%20issuer%2C%0A%2Fadmin%2F%20and%20%2Frealms%2Fmaster%2F%20return%20404%20on%20localhost%3A8000%2C%20the%20console%0Areturns%20200%20on%20localhost%3A8080%2C%20temp-admin%20is%20gone%2C%20the%20backup%20timer%20is%0Aenabled%20and%20the%20backup%20test%20passes.%20Do%20not%20reboot.%0ANever%20paste%20a%20password%20into%20the%20chat%3B%20say%20the%20admin%20password%20is%0AADMIN_PASSWORD%20in%20~%2Fkeycloak%2F.env.%20Finish%20by%20pointing%20the%20owner%20to%0A%22Open%20the%20admin%20console%22%20and%20%22Open%20the%20login%20pages%22.%0A%0AFinish%20with%20the%20URLs%20I%20should%20open.%0A",
    "terminal": "curl -fsSL https://exe.dev/deploy/keycloak/prompt.txt | ssh exe.dev new --prompt=/dev/stdin",
    "prompt": "Set up Keycloak on this VM by following the exe.dev recipe at https://exe.dev/deploy/keycloak.md?via=deploy from top to bottom.\n\nThe recipe's example VM name is my-keycloak. This VM's name is the output of `hostname`: use it wherever the recipe writes my-keycloak. Skip the step that creates the VM; you are on it.\n\nYou are done when all of these are true. Check each one yourself:\n- Keycloak in production mode on PostgreSQL, with its URLs set for exe.dev's HTTPS proxy.\n- A permanent admin account in place of the temporary one, with its password in a file only you can read.\n- An apps realm for your users, with brute-force protection on.\n- A public port that serves only realm logins, and refuses the admin console and master realm.\n- Nightly database backups, with one restored into a scratch database to check it.\n- Everything starts again after a reboot.\n\nRead the whole recipe, including the closed details. For initial setup,\nfollow \"Install by hand\" first, skipping VM creation and SSH: Docker,\nthe settings, starting Keycloak, replacing the temporary admin, the apps\nrealm, nginx, the backup timer, and the backup test. The walkthrough at\nthe top is for the owner afterwards.\nWork as exedev in ~/keycloak. Never overwrite an existing .env. Don't\ncreate users or clients, set up SMTP or connect apps unless the owner\nasks. Don't run Restore or Update. You can't make the VM public from\nthe VM; leave that to the owner, and don't ask them to until you're done.\nVerify docker.service and nginx are enabled, both containers use\nunless-stopped and are healthy, the apps realm's discovery document on\nlocalhost:8000 names https://\u003cvm\u003e.exe.xyz/realms/apps as its issuer,\n/admin/ and /realms/master/ return 404 on localhost:8000, the console\nreturns 200 on localhost:8080, temp-admin is gone, the backup timer is\nenabled and the backup test passes. Do not reboot.\nNever paste a password into the chat; say the admin password is\nADMIN_PASSWORD in ~/keycloak/.env. Finish by pointing the owner to\n\"Open the admin console\" and \"Open the login pages\".\n\nFinish with the URLs I should open.\n",
    "prompt_url": "https://exe.dev/deploy/keycloak/prompt.txt"
  },
  "published": "2026-11-21",
  "updated": "2026-11-21",
  "verified": "2026-11-21",
  "related": [
    "grafana",
    "postgres",
    "vaultwarden",
    "penpot",
    "docker-compose",
    "agent-secrets"
  ],
  "alternatives": [
    "Auth0",
    "Okta",
    "Authentik"
  ],
  "files": [
    "https://exe.dev/deploy/keycloak/backup.sh",
    "https://exe.dev/deploy/keycloak/compose.yaml",
    "https://exe.dev/deploy/keycloak/kcadm",
    "https://exe.dev/deploy/keycloak/nginx.conf"
  ]
}
