Installing ZITADEL on a VPS: self-hosted IAM, PostgreSQL, SSL, SMTP, and backups
TL;DR
ZITADEL can be deployed on your own VPS as a unified identity and access management service: with PostgreSQL, HTTPS, SMTP, MFA, organizations, projects, and OAuth 2.0/OpenID Connect. This guide uses Docker Compose, PostgreSQL 16, Caddy for automatic TLS, and restic for encrypted backups.
- For a small production installation, 2 vCPU, 4 GB RAM, and an SSD of at least 40 GB are sufficient.
- ZITADEL runs in Docker, while PostgreSQL stores users, organizations, projects, and settings.
- The domain points to the VPS, and Caddy automatically obtains a Let’s Encrypt certificate.
- SMTP is required for invitations, password recovery, notifications, and MFA codes.
- Backups include PostgreSQL, the Compose configuration, secrets, and the ZITADEL master key.
1. TL;DR
ZITADEL is a self-hosted IAM platform for centralized authentication of users, services, and administrators. It supports OpenID Connect, OAuth 2.0, SAML, WebAuthn, MFA, organizations, and a project-based access model. In this guide, the service is hosted on Ubuntu Server 24.04 LTS, PostgreSQL runs in a separate container, and external access passes through Caddy.
The commands are intended for a clean server with a public IPv4 address and the auth.example.com domain. Before running them, replace this domain, passwords, email address, and S3 values with your own.
- System: Ubuntu Server 24.04 LTS, Docker Engine 28.x or newer, Docker Compose v2.
- Application: ZITADEL 4.x; the image is pinned to a specific tag rather than
latest. - Database: PostgreSQL 16.x in Docker Compose.
- Proxy: Caddy 2.10.x with an automatic Let’s Encrypt certificate.
- Backup:
pg_dumpand restic to S3-compatible object storage.
2. Contents
The article is structured as a practical scenario: first the server is selected, then basic system hardening is performed, after which the containers are launched and the domain, TLS, SMTP, and backups are configured.
- Task and architecture review.
- VPS or dedicated server resource calculation.
- Creating a separate administrator and configuring SSH.
- Installing Docker and preparing directories.
- Launching PostgreSQL and ZITADEL.
- Configuring Caddy, HTTPS, and SMTP.
- Checking OAuth/OIDC, healthcheck, and logs.
- Automated backups, restoration, and updates.
3. What we are configuring and why
The role of ZITADEL in the infrastructure
Without IAM, each web service usually stores its own users, passwords, roles, and sessions. This results in multiple account databases, different MFA policies, and complicated employee access removal. ZITADEL separates authentication into a dedicated service: the application redirects the user to the login page, receives a signed token, and checks the user's permissions.
The practical result is single sign-on for internal panels, SaaS applications, Mattermost, Git services, VPN portals, and custom APIs. Standard OpenID Connect is used for integrations, so the application does not need to know the user's password or implement access recovery itself.
Architecture of this guide
| Component | Purpose | Public access |
|---|---|---|
| Caddy | HTTPS, reverse proxy, automatic certificate renewal | TCP 80 and 443 |
| ZITADEL | IAM, OIDC, OAuth 2.0, administrative interface | Only through Caddy |
| PostgreSQL 16 | Storing ZITADEL state | Internal Docker network only |
| restic | Encrypting and sending backups | Outgoing connections to S3 |
What will be ready after completion
- Administrative console address:
https://auth.example.com/ui/console. - PostgreSQL with no publicly exposed port.
- HTTPS with a valid certificate and automatic renewal.
- SMTP for invitations and account recovery.
- OIDC-compatible IAM for multiple applications.
- Daily encrypted backup of the database and configuration.
Self-hosted or cloud-managed
Cloud IAM reduces operational workload: the provider is responsible for updates, redundancy, availability, and some security measures. This is convenient if IAM is not a critical infrastructure control or the team is not prepared to respond to outages independently.
Self-hosted ZITADEL on a VPS is suitable when control over data, predictable costs, a custom domain, and the ability to isolate IAM in a chosen jurisdiction are important. The downside is that the owner is responsible for patches, monitoring, secrets, SMTP, backups, and recovery. IAM cannot be considered reliable merely because the container is running: the recovery procedure must be tested regularly.
Limitations
ZITADEL does not replace LDAP for all legacy applications, although specific integration scenarios are possible. It is also not a secrets management system for servers. Database passwords, the master key, and restic keys should be stored separately from the source code and preferably in a secrets manager.
4. What VPS configuration is required for this task
Minimum configuration
For a test environment and a small team of a few dozen users, 2 vCPU, 4 GB RAM, and a 40 GB SSD are sufficient. A minimum of 2 GB RAM is possible, but when PostgreSQL, ZITADEL, Caddy, Docker, and the backup process run simultaneously, there is practically no spare capacity.
| Scenario | CPU | RAM | Disk | Network |
|---|---|---|---|---|
| Testing | 1–2 vCPU | 2–4 GB | 30–40 GB SSD | 100 Mbps |
| Small production team | 2–4 vCPU | 4–8 GB | 60–100 GB NVMe | 100–1000 Mbps |
| Many organizations and applications | 4–8 vCPU | 8–16 GB | 100+ GB NVMe | 1 Gbps |
For a typical installation, you can choose a VPS with these specifications: 2–4 vCPU, 4–8 GB RAM, at least 60 GB SSD/NVMe, a public IPv4 address, and the ability to open TCP 80 and 443. The disk must account for more than just the database: logs, Docker image updates, and temporary dump files can consume several gigabytes.
When a dedicated server is needed
A separate physical server is usually not required for a single ZITADEL instance. A dedicated server is justified if IAM runs alongside a large number of services, the database contains tens or hundreds of thousands of objects, guaranteed resources without neighboring tenants are required, or security policy prohibits virtualization on a shared host.
One dedicated server is also insufficient for high availability: if the disk or power fails, the service will still stop. Two independent nodes, PostgreSQL replication, an external load balancer, and tested recovery are more important. For most small installations, it is better to start with a VPS and store backups separately.
Location and network
Choose a region close to your users and applications. Distance affects the latency of OIDC redirects, console loading speed, and API response time. If applications are located in multiple regions, place IAM where most users are located, or use a CDN and a separate high-availability architecture.
A public IPv4 address, a correctly configured PTR record—preferably for the mail infrastructure—and the ability to configure DNS records are required. For Caddy, the domain must point to the VPS before the proxy is launched; otherwise, Let’s Encrypt certificate issuance will fail.
5. Server preparation
Logging in and updating Ubuntu
Connect to the server using the temporary user provided by the provider. All commands below are executed by a user with sudo privileges. The example uses Ubuntu 24.04 LTS with the amd64 or arm64 system architecture.
# Проверяем версию системы и обновляем пакеты
cat /etc/os-release
sudo apt update && sudo apt full-upgrade -y
# Устанавливаем базовые инструменты
sudo apt install -y ca-certificates curl gnupg lsb-release \
git jq unzip vim ufw fail2ban unattended-upgrades
After updating the kernel, check whether a reboot is required. If the kernel or critical system libraries have changed, restart the server during an agreed maintenance window.
# Показываем, требуется ли перезагрузка
if [ -f /var/run/reboot-required ]; then echo "Требуется reboot"; fi
# После согласования окна обслуживания
sudo reboot
Separate user and SSH keys
Do not use root for routine work. Create an administrator, add a public key, and disable password authentication only after verifying the new login. Do not close the current SSH session until the new session has been confirmed.
# Создаём отдельного администратора
sudo adduser deploy
sudo usermod -aG sudo deploy
# Создаём каталог SSH и добавляем ваш публичный ключ
sudo install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
sudo nano /home/deploy/.ssh/authorized_keys
sudo chown deploy:deploy /home/deploy/.ssh/authorized_keys
sudo chmod 600 /home/deploy/.ssh/authorized_keys
Insert one line containing the ssh-ed25519 key into the authorized_keys file. After verifying the connection, modify the SSH configuration.
# Отключаем root-вход и пароли после проверки ключевого доступа
sudo tee /etc/ssh/sshd_config.d/10-hardening.conf > /dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 4
EOF
# Проверяем синтаксис и перечитываем конфигурацию SSH
sudo sshd -t && sudo systemctl reload ssh
Firewall and fail2ban
Open SSH, HTTP, and HTTPS. If SSH runs on a non-standard port, replace the value in the rule. Do not expose the PostgreSQL port externally: the containers will communicate through the internal Docker network.
# Разрешаем только необходимые входящие соединения
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment 'SSH'
sudo ufw allow 80/tcp comment 'HTTP for ACME'
sudo ufw allow 443/tcp comment 'HTTPS'
sudo ufw --force enable
sudo ufw status verbose
# Запускаем защиту от перебора SSH
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
Docker publishes ports through its own iptables/nftables rules. Therefore, PostgreSQL should not be published through Compose even when UFW is enabled. Check the list of listening ports after starting the services.
6. Software Installation — Step by Step
Installing Docker Engine and Compose
Use the official Docker repository rather than outdated packages from random scripts. In 2026, Docker Engine 28.x and Docker Compose v2 are sufficient for this guide. Installation should not be performed via an unverified curl script from an unknown source.
# Add the official Docker repository key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the Docker repository for the current Ubuntu release
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Engine, CLI, Buildx, and Compose plugin
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
# Check versions and enable automatic startup
sudo docker version
sudo docker compose version
sudo systemctl enable --now docker
Adding a user to the docker group allows Docker to be run without sudo, but effectively grants root privileges. On a production server, you can keep using commands through sudo; this reduces the risk of accidentally launching a dangerous container from a regular shell session.
Creating Project Directories
# Create separate directories for configuration, data, and backups
sudo install -d -m 750 /opt/zitadel
sudo install -d -m 750 /opt/zitadel/caddy
sudo install -d -m 750 /opt/zitadel/postgres
sudo install -d -m 750 /opt/zitadel/backups
sudo chown -R deploy:deploy /opt/zitadel
# Change to the application directory
cd /opt/zitadel
The Compose configuration below uses PostgreSQL 16 and ZITADEL 4.x. Pin a specific verified image tag, for example ghcr.io/zitadel/zitadel:v4.0.0, if this tag is available in the official registry at the time of installation. Before deploying to production, check the current stable release and migration notes in the official ZITADEL documentation.
Preparing the Secrets File
Secrets must not be committed to Git, exposed in public logs, or included in commands saved in shell history. Create a .env file, restrict its permissions, and add it to Git exclusions. The master key must be stored in a separate secure location: without it, a restored ZITADEL database may be unusable.
# Generate random values and create a protected .env
cd /opt/zitadel
umask 077
POSTGRES_PASSWORD="$(openssl rand -base64 36 | tr -dc 'A-Za-z0-9' | head -c 32)"
MASTER_KEY="$(openssl rand -base64 48 | tr -dc 'A-Za-z0-9' | head -c 32)"
RESTIC_PASSWORD="$(openssl rand -base64 48 | tr -dc 'A-Za-z0-9' | head -c 40)"
cat > .env <<EOF
ZITADEL_DOMAIN=auth.example.com
ZITADEL_IMAGE=ghcr.io/zitadel/zitadel:v4.0.0
POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ZITADEL_MASTERKEY=${MASTER_KEY}
RESTIC_PASSWORD=${RESTIC_PASSWORD}
EOF
chmod 600 .env
grep -v 'PASSWORD\|MASTERKEY' .env
Docker Compose
Create the compose.yaml file. PostgreSQL has no ports section, so the database is accessible only to the ZITADEL container on the iam network. The restart: unless-stopped policy restarts the service after a failure but does not replace monitoring.
name: zitadel
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: zitadel
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: zitadel
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U zitadel -d zitadel"]
interval: 10s
timeout: 5s
retries: 10
networks:
- iam
zitadel:
image: ${ZITADEL_IMAGE}
restart: unless-stopped
command: start-from-init --masterkeyfile /run/secrets/zitadel_masterkey
depends_on:
postgres:
condition: service_healthy
environment:
ZITADEL_DATABASE_POSTGRES_HOST: postgres
ZITADEL_DATABASE_POSTGRES_PORT: "5432"
ZITADEL_DATABASE_POSTGRES_DATABASE: zitadel
ZITADEL_DATABASE_POSTGRES_USER_USERNAME: zitadel
ZITADEL_DATABASE_POSTGRES_USER_PASSWORD: ${POSTGRES_PASSWORD}
ZITADEL_EXTERNALDOMAIN: ${ZITADEL_DOMAIN}
ZITADEL_EXTERNALSECURE: "true"
ZITADEL_TLS_ENABLED: "false"
ZITADEL_FIRSTINSTANCE_ORG_HUMAN_USERNAME: admin
ZITADEL_FIRSTINSTANCE_ORG_HUMAN_EMAIL: [email protected]
ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD: CHANGE_THIS_FIRST_PASSWORD
secrets:
- zitadel_masterkey
expose:
- "8080"
networks:
- iam
caddy:
image: caddy:2.10-alpine
restart: unless-stopped
depends_on:
- zitadel
ports:
- "80:80"
- "443:443"
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- iam
secrets:
zitadel_masterkey:
file: ./secrets/masterkey
volumes:
postgres_data:
caddy_data:
caddy_config:
networks:
iam:
driver: bridge
The initial administrator password in the example must be replaced before starting. For production, use a long random password, then enable MFA after the first login and create a separate administrator account. Do not leave the value CHANGE_THIS_FIRST_PASSWORD.
# Create a master key file matching the value in .env
set -a
. /opt/zitadel/.env
set +a
sudo install -d -m 700 /opt/zitadel/secrets
printf '%s' "$ZITADEL_MASTERKEY" | sudo tee /opt/zitadel/secrets/masterkey > /dev/null
sudo chmod 600 /opt/zitadel/secrets/masterkey
sudo chown -R deploy:deploy /opt/zitadel/secrets
# Validate the Compose configuration without starting containers
docker compose config
# Pull images
docker compose pull
# Start PostgreSQL and ZITADEL in the background
docker compose up -d postgres zitadel
# View the status and latest logs
docker compose ps
docker compose logs --tail=100 zitadel
On the first launch, ZITADEL initializes the database schema. This may take several minutes. If the container exits, examine the logs first instead of rerunning random migration commands. An error in the master key or PostgreSQL connection must be fixed in the configuration.