How can I automatically configure the admin user for a self-hosted n8n deployment?

I’m running a self-hosted n8n instance using Docker and I need to automatically set up the administrator account during deployment. Our CI/CD pipeline requires an n8n API token for automated testing and production workflows, so manual setup through the web interface isn’t practical.

Here’s my current Docker setup with a PostgreSQL database:

postgres:
  image: postgres:13
  ports:
    - "5433:5432"
  environment:
    POSTGRES_DB: n8n_workflow
    POSTGRES_USER: dbuser
    POSTGRES_PASSWORD: dbpass
    PGDATA: /var/lib/postgresql/data/postgres
  volumes:
    - ./data/postgres/:/var/lib/postgresql/data
    - ./scripts/init:/docker-entrypoint-initdb.d:ro

workflow-engine:
  image: docker.n8n.io/n8nio/n8n
  ports:
    - "5679:5678"
  environment:
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_DATABASE=n8n_workflow
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_USER=dbuser
    - DB_POSTGRESDB_PASSWORD=dbpass
  volumes:
    - ./data/n8n:/home/node/.n8n
    - ./shared:/shared

Since I have direct access to the PostgreSQL database, I’m wondering if there’s a way to insert the admin user directly into the database tables or use environment variables to bypass the initial setup wizard. Has anyone found a solution for this?

you could also use docker secrets or init containers. just pipe the owner setup through a curl command that hits the api endpoint right after the container starts up. works great for automated deployments - no need to mess with the database directly.

You don’t need to mess with the database directly. I hit the same issue with our containerized setup and found n8n handles this automatically with environment variables. Just set N8N_OWNER_EMAIL, N8N_OWNER_PASSWORD, and N8N_OWNER_FIRST_NAME in your workflow-engine service config. On first startup with an empty database, n8n creates the admin account automatically - no manual steps needed. Watch out though - your database needs to be ready before n8n starts or the auto-creation fails silently. I’d add a health check or startup delay to make sure PostgreSQL is up. Once deployed, you can use those admin credentials to generate API tokens through the REST API for your CI/CD workflows.

I hit this same issue when deploying n8n in our Kubernetes cluster. Here’s what worked: add N8N_OWNER_EMAIL and N8N_OWNER_PASSWORD environment variables to your workflow-engine service config. When n8n starts up and sees these variables with an empty user table, it’ll auto-create the owner account - no web setup wizard needed. I’d also throw in N8N_SKIP_OWNER_SETUP=true to skip any interactive prompts entirely. Once the container’s up, use those owner credentials to authenticate with the API and generate tokens for your CI/CD pipeline. We’ve been running this setup in production for six months with zero issues.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.