How can I automatically configure admin user during n8n self-hosted deployment?

I’m running a self-hosted n8n setup in my infrastructure and need to automate the admin user creation process. Our deployment workflow requires an API key from n8n to work properly in both testing and production environments. Right now I have to manually complete the owner setup through the web interface every time we deploy.

Here’s my current docker setup with MySQL backend:

mysql:
  image: mysql:8.0
  ports:
    - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: rootpass
    MYSQL_DATABASE: automation
    MYSQL_USER: dbuser
    MYSQL_PASSWORD: dbpass
  volumes:
    - ./storage/mysql:/var/lib/mysql
    - ./scripts/init:/docker-entrypoint-initdb.d:ro

automation:
  image: docker.n8n.io/n8nio/n8n
  ports:
    - "5679:5678"
  environment:
    - DB_TYPE=mysqldb
    - DB_MYSQLDB_DATABASE=automation
    - DB_MYSQLDB_HOST=mysql
    - DB_MYSQLDB_PORT=3306
    - DB_MYSQLDB_USER=dbuser
    - DB_MYSQLDB_PASSWORD=dbpass
  volumes:
    - ./storage/app:/home/node/.n8n
    - ./uploads:/uploads

Since I have database access, maybe I could insert the admin user directly into the MySQL tables during initialization. Has anyone found a way to skip the manual setup and create the owner account programmatically?

I’ve run into this same issue with our CI/CD pipeline. Best solution is hitting n8n’s REST API to create the owner account after the container spins up. Set up a health check that waits for n8n to be ready, then POST to /rest/owner/setup with your admin creds. Timing’s the tricky bit - n8n has to fully boot first. I built a bash script that pings /rest/login until it shows the setup page, then immediately fires the owner creation request. Way better than messing with the database directly, which could break when n8n updates. API method works across versions and is much easier to maintain.

Environment variables r your easiest option. n8n has N8N_OWNER_EMAIL and N8N_OWNER_PASSWORD vars that auto-create the admin on first startup. Just add them to yr docker compose to skip the manual setup totally. Much cleaner than API calls or db meddling.

Direct database manipulation worked for me when I automated this in our k8s deployment. You’ll need to hash the password properly though - n8n uses bcrypt with salt rounds. I created an init script that runs after schema creation but before n8n starts. The key tables are user and settings - insert your admin into the user table with the proper password hash and set the instance as initialized in settings. Make sure you set the correct user role and global scope. This gives you full control over timing and doesn’t depend on API availability during container startup. Just remember to update your init script when you upgrade n8n versions since the schema might change.

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