What you will set up
authentik is an identity provider: it holds your users, their passwords and their second factors, and your apps let authentik check who is logging in. Each person has one account for everything, and when someone leaves, you turn off one account instead of one in every app. Apps connect to it with OpenID Connect, SAML or LDAP, which most self-hosted apps support.
Here it runs as three Compose services with PostgreSQL, under a user of its own called authentik, behind Caddy from the rootless Docker guide. As an example, it becomes the login for the Matrix server from the Matrix guide.
The Docker setup follows our tested rootless Docker guide on Debian 13. The app version and the app-specific behaviour below come from the tested Podman guide on a Melonslab server; the Docker steps for this app were not re-tested end to end. In the Podman test, authentik used between 700 MB and 1 GB of memory and PostgreSQL about 30 MB, so allow at least 2 GB on the server.
The Podman test also covered the first setup through an SSH tunnel, single sign-on to Matrix, enforced two-factor authentication, the password policy and failed-login reputation, a test email, an uploaded file surviving a restart, a reboot, and a restore from backup.
authentik's interface and emails were tested in English. It also has, for example, Norwegian, Finnish and German.
Before you start
You need:
- a server set up as in the rootless Docker guide, with Caddy running, and at least 2 GB of memory;
- an A record and an AAAA record for
auth.example.compointing at your server; - an email account that can send through your email provider's SMTP server, such as
auth@example.com.
The examples use auth.example.com for authentik and 203.0.113.10 for your server's IPv4 address, which ip -brief address show eth0 shows. Replace them throughout.
1. Create the user
As root:
useradd -m -s /bin/bash -U authentik
loginctl enable-linger authentik
mkdir -p /home/authentik/authentik/data /home/authentik/authentik/db
chown -R authentik:authentik /home/authentik/authentik
Do not add the user to the docker group. The daemon is rootless and belongs to this user.
2. Create the secrets
As root, generate the passwords and write them to files that only authentik can read:
umask 077
db_password=$(openssl rand -hex 24)
printf 'POSTGRES_PASSWORD=%s\n' "$db_password" > /home/authentik/authentik/db.env
printf 'AUTHENTIK_POSTGRESQL__PASSWORD=%s\n' "$db_password" > /home/authentik/authentik/secrets.env
printf 'AUTHENTIK_SECRET_KEY=%s\n' "$(openssl rand -base64 60)" >> /home/authentik/authentik/secrets.env
chown authentik:authentik /home/authentik/authentik/db.env /home/authentik/authentik/secrets.env
chmod 600 /home/authentik/authentik/db.env /home/authentik/authentik/secrets.env
The first value is the database password; the same value goes to PostgreSQL and authentik. The second is authentik's secret key, which signs its sessions and tokens. Compose passes these files in as environment variables through env_file, so no secret appears in compose.yaml. Back both files up as in step 13.
3. Describe the Compose services
Create /home/authentik/authentik/compose.yaml:
cat > /home/authentik/authentik/compose.yaml <<'YAML'
services:
db:
image: docker.io/library/postgres:18-alpine
env_file: db.env
environment:
POSTGRES_USER: authentik
POSTGRES_DB: authentik
volumes:
- ./db:/var/lib/postgresql
restart: always
server:
image: ghcr.io/goauthentik/server:2026.8
command: server
env_file:
- authentik.env
- secrets.env
environment:
AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS: "203.0.113.10/32"
ports:
# Only Caddy, on this server, can reach authentik: the port is not open to the internet.
- "127.0.0.1:8092:9000"
shm_size: 512m
volumes:
- ./data:/data
depends_on:
- db
restart: always
worker:
image: ghcr.io/goauthentik/server:2026.8
command: worker
env_file:
- authentik.env
- secrets.env
environment:
AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS: "203.0.113.10/32"
# The server already uses these ports.
AUTHENTIK_LISTEN__HTTP: "[::]:9001"
AUTHENTIK_LISTEN__METRICS: "[::]:9301"
shm_size: 512m
volumes:
- ./data:/data
depends_on:
- db
restart: always
YAML
And /home/authentik/authentik/authentik.env, the settings both services share:
AUTHENTIK_POSTGRESQL__HOST=db
AUTHENTIK_POSTGRESQL__USER=authentik
AUTHENTIK_POSTGRESQL__NAME=authentik
# Caddy's connections reach the container from the server's own IPv4 address.
The server answers web requests, and the worker runs background tasks. Both run the same image. Compose puts them on one network, where the database has the name db. In the pod of the Podman guide they shared a network, so the worker's two ports had to be moved away from the server's. authentik trusts the address Caddy sends for each visitor only from TRUSTED_PROXY_CIDRS; with Caddy on this server, its connections come from the server's own IPv4 address.
The tag 2026.8 gets every fix to authentik 2026.8. Step 12 covers moving to the next version.
4. Start it
uid=$(id -u authentik)
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose pull && docker compose up -d && docker compose logs -f"
The first start downloads the images, and then authentik sets up its database, which took about three minutes on the Podman test server. Press Ctrl+C and check it:
uid=$(id -u authentik)
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8092/-/health/ready/"
It answers 503 while authentik is still starting, and 200 when it is ready. Until then, the worker's log shows warnings about missing tables, which stop by themselves.
5. Create the admin account
Until the admin account has a password, whoever opens authentik first gets to set it. That is why its port is on 127.0.0.1 only, and why you do this through SSH, before Caddy puts authentik on the internet. From your own computer:
ssh -L 8092:127.0.0.1:8092 root@203.0.113.10
Keep that session open, and open http://localhost:8092 in your browser. authentik shows its first setup page for its admin user, akadmin. Enter your email address and a strong password twice. Base URL shows the tunnel's address, http://localhost:8092: change it to https://auth.example.com, and choose Continue.
authentik logs you in as akadmin straight away, and the setup page is closed from then on. Close the SSH session.
6. Put Caddy in front
As root, add this block at the end of /home/caddy/Caddyfile:
auth.example.com {
reverse_proxy 127.0.0.1:8092
}
chown caddy:caddy /home/caddy/Caddyfile
uid=$(id -u caddy)
runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$uid \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
bash -lc "export DOCKER_HOST=unix:///run/user/$uid/docker.sock; cd /home/caddy/caddy && docker compose restart caddy"
Log in at https://auth.example.com as akadmin. The admin interface is at https://auth.example.com/if/admin/.
7. Add your users
In the admin interface:
- Open Directory, then Users, and choose New User.
- Choose Internal User, and enter a Username, a Display Name and an Email Address. Choose Create.
- Choose the new user in the list. Under Recovery, choose Set password, enter a password, and choose Set Password.
The person logs in at https://auth.example.com, and can change the password under the gear icon, in User details.
8. Email
authentik sends email from flows that have an email stage, such as a password reset or an email confirmation at sign-up, and for notifications you choose to get by email. The setup in this guide has none of those yet, so nothing stops working without email. Set it up before you add such a flow.
As root, add the SMTP password to the 0600 secret file, then add the settings to /home/authentik/authentik/authentik.env:
umask 077
printf 'AUTHENTIK_EMAIL__PASSWORD=%s\n' 'the-smtp-password' >> /home/authentik/authentik/secrets.env
cat >> /home/authentik/authentik/authentik.env <<'ENV'
AUTHENTIK_EMAIL__HOST=smtp.example.com
AUTHENTIK_EMAIL__PORT=587
AUTHENTIK_EMAIL__USE_TLS=true
AUTHENTIK_EMAIL__USERNAME=auth@example.com
AUTHENTIK_EMAIL__FROM=auth@example.com
ENV
chown authentik:authentik /home/authentik/authentik/authentik.env /home/authentik/authentik/secrets.env
Use your own server, account and sender address. Compose picks up both files when the services are recreated. Restart, wait for the health check from step 4 to answer 200, and send a test email:
uid=$(id -u authentik)
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose up -d && docker compose exec -T worker ak test_email you@example.com"
USE_TLS=true on port 587 uses STARTTLS. For port 465, which uses TLS from the start, set the port to 465 and replace AUTHENTIK_EMAIL__USE_TLS=true with AUTHENTIK_EMAIL__USE_SSL=true. We sent the test email to a test mail catcher on the server, not through a real email provider.
9. Require two-factor authentication
Out of the box, two-factor authentication is up to each person. To require it for everyone, open Flows and Stages, then Stages, in the admin interface, and edit default-authentication-mfa-validation:
- Under Device classes, keep Static Tokens, TOTP Authenticators and WebAuthn Authenticators.
- Set Not configured action to Force the user to configure an authenticator.
- Under Configuration stages, move default-authenticator-totp-setup to Selected Stages.
- Choose Update.
At their next login, after the password, everyone without an authenticator, akadmin too, sees a QR code. They scan it with an authenticator app, such as the one built into their phone's password manager, and enter the code it shows. From then on, authentik asks for a code from the app after the password.
Under the gear icon, then Credentials and MFA Devices, each person can add a WebAuthn device, for passkeys and security keys, and Static tokens, one-time codes to print and keep in case the phone is lost.
10. Passwords and failed logins
authentik comes with a password policy, default-password-change-password-policy, which checks new passwords when people change their own. It asks for 8 characters and rejects easily guessed passwords. To ask for 12, open Customization, then Policies, edit the policy, set Minimum length to 12, and choose Update. Leave Check haveibeenpwned.com off unless you want authentik to send the start of each new password's hash to that service. Passwords you set for someone under Set password in the admin interface are not checked, so make those long.
authentik has no lockout counter as such. It keeps a reputation score for each username and address: each failed login, a wrong password or a wrong code, lowers it by one, and each successful login raises it by one, between -5 and 5. A reputation policy acts on that score. To stop logins at -5:
- Under Customization, then Policies, choose Create, then Reputation Policy. Name it
failed-logins, keep Check IP and Check Username on and Threshold at-5, and choose Finish. - Under Flows and Stages, then Stages, choose Create, then Deny Stage. Name it
too-many-failed-logins, enter a Deny message such asToo many failed logins. Try again tomorrow, or ask an admin., and choose Finish. - Under Flows and Stages, then Flows, open default-authentication-flow, then Stage Bindings, and choose Bind existing stage. Choose
too-many-failed-logins, set Order to15, turn Evaluate when flow is planned off and Evaluate when stage is run on, and choose Create. - Expand the new binding in the list, choose Bind existing policy/group/user, choose the policy
failed-logins, and choose Create.
The deny stage now runs after the username, and only when the score is at -5 or lower. In the Podman test, after five wrong passwords, the right one never got asked for: authentik showed the deny message. Know what it does and does not do:
- It is not a timed lock. A score is forgotten 24 hours after its last change, or when an admin deletes it under Customization, then Reputation scores.
- The policy adds up the scores of the username from every address, and of the address for every username. Someone who knows a username can lock that person out from anywhere, and five failures from one office address lock out everyone there. Turning off Check IP or Check Username trades one of those for the other.
- A user who has just logged in successfully a few times has a score above 0, and gets more tries.
11. Connect an app
Each app gets an application and a provider in authentik. Here the app is Matrix: people then log in to Element with their authentik account. In the admin interface:
- Open Applications, then Applications, and choose New Application.
- Enter
Matrixas the Application Name, and choose Next. - Choose OAuth2/OpenID Provider, and Next.
- Set Authorization Flow to default-provider-authorization-implicit-consent, which logs people in without asking them to approve the app each time.
- Copy the Client ID and Client Secret.
- Under Redirect URIs/Origins, choose Add entry, keep Strict, and enter
https://matrix.example.com/_synapse/client/oidc/callback. - Choose Next twice, then Create Application, and Finish.
Without anything under Configure Bindings, every user in authentik can log in to the app. authentik's address for the app is https://auth.example.com/application/o/matrix/, with the name in lower case.
Then add this to the Synapse configuration in /home/matrix/matrix/synapse.yaml, with the ID and secret you copied:
oidc_providers:
- idp_id: authentik
idp_name: authentik
discover: true
issuer: "https://auth.example.com/application/o/matrix/"
client_id: "CLIENT_ID"
client_secret: "CLIENT_SECRET"
scopes: ["openid", "profile", "email"]
allow_existing_users: true
user_mapping_provider:
config:
localpart_template: "{{ user.preferred_username }}"
display_name_template: "{{ user.name }}"
authentik runs on the same server, so Synapse has to reach it through the server rather than inside its own Compose network. In the Matrix Compose file, add this under the matrix service:
extra_hosts:
- "auth.example.com:host-gateway"
Then recreate the Matrix service from /home/matrix/matrix with docker compose up -d, as matrix.
Element's login page now has Continue with authentik. A person logging in for the first time gets a Matrix account with their authentik user name, such as @bob:example.com. With allow_existing_users: true, an authentik user with the same name as an existing Matrix account logs in to that account, so turn it on only if the names in authentik belong to the same people as in Matrix.
Other apps follow the same steps, with the redirect address from the app's own documentation. authentik's documentation has a page for many of them.
12. Keep it up to date
Add the weekly docker-update.service and docker-update.timer from the rootless Docker guide, with WorkingDirectory=/home/authentik/authentik, and enable the timer as authentik. It pulls new images and recreates the services; that keeps authentik on the newest 2026.8 release and PostgreSQL on the newest 18.
authentik releases a new version every few months, such as 2026.11. Upgrade one version at a time, without skipping any, because authentik cannot go back to an older version: read the release notes, back up as in step 13, change the image tag in both the server and worker services of compose.yaml, and run docker compose pull && docker compose up -d as authentik.
13. Back up
As root, with authentik running:
umask 077
mkdir -p /home/authentik/backup
chown authentik:authentik /home/authentik/backup
uid=$(id -u authentik)
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose exec -T db pg_dump -U authentik authentik > /home/authentik/backup/authentik-db.sql"
tar -czf /home/authentik/backup/authentik-data.tar.gz -C /home/authentik/authentik data
tar -czf /home/authentik/backup/authentik-secrets.tar.gz -C /home/authentik/authentik db.env secrets.env
The files are readable by root only. The database holds the users, their passwords and second factors, and every application. The secret key is needed to restore it. Copy /home/authentik/backup to another machine, for example with restic, and keep it private.
To restore into an empty database:
uid=$(id -u authentik)
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose down"
rm -rf /home/authentik/authentik/db /home/authentik/authentik/data
tar -xzf /home/authentik/backup/authentik-data.tar.gz -C /home/authentik/authentik
tar -xzf /home/authentik/backup/authentik-secrets.tar.gz -C /home/authentik/authentik
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose up -d db && docker compose stop server worker"
uid=$(id -u authentik)
until runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose exec -T db pg_isready -q -h 127.0.0.1 -U authentik"; do sleep 2; done
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose exec -T db psql -q -U authentik -d authentik < /home/authentik/backup/authentik-db.sql"
runuser -u authentik -- env HOME=/home/authentik XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/authentik/authentik && docker compose up -d server worker"
Starting the database alone avoids authentik setting up an empty database before the backup is loaded. The until line waits for PostgreSQL to be ready. On a new server, the restored secrets.env already holds the secret key and the email password, so do not generate new ones in step 2. We restored on the same server in the Podman test.
Troubleshooting
An app's login fails, and https://auth.example.com/application/o/matrix/.well-known/openid-configuration shows addresses starting with http://. authentik does not trust Caddy. Check AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS in step 3: it must be your server's IPv4 address. Then restart the server with docker compose restart server as authentik from /home/authentik/authentik.
The first setup page shows Not Found. authentik is still setting itself up. Wait a minute after the health check in step 4 answers 200, and open http://localhost:8092 again.
Synapse cannot reach authentik. The extra_hosts entry from step 11 is missing from the Matrix Compose file, or names a different host.
Login stops after the username with "Too many failed logins". The reputation policy from step 10 has blocked the username or the address. Delete the score under Customization, then Reputation scores.