Copying .env files between your laptop and the server is how secrets leak into Slack, git, and support tickets. Run one self-hosted secrets manager and both sides pull from the same place. No more copying.
The problem
Your app needs the same variables in two places. So you copy the file, or paste a value into chat, or commit it "just this once".
laptop/.env ──copy──> server/.env
│ │
└──── drift ─────────┘ (leaks, git risk, "works on my machine")
Two copies drift. One gets a new key, the other doesn't. Then a deploy fails because DATABASE_URL is stale.
What Infisical is
Infisical is a secrets manager you can run yourself. It's open-source at the core, with a UI, a CLI, and the concept of environments: dev, prod, staging.
You store secrets once. Then:
- Your laptop pulls them with the CLI.
- Your server pulls them with a machine identity.
Secrets stay encrypted at rest. A real dashboard replaces a folder full of .env files.
Set it up: Docker Compose
Docker Compose is the fastest way to get one running on a small server.
- Download the Compose file and a starter env:
curl -o docker-compose.prod.yml https://raw.githubusercontent.com/Infisical/infisical/main/docker-compose.prod.yml
curl -o .env https://raw.githubusercontent.com/Infisical/infisical/main/.env.example
This pulls the stack definition (backend + Postgres + Redis) and a template of the required settings.
- Open
.envand set the URL your CLI and browser will use:
SITE_URL=https://{YOUR_DOMAIN}
This must match how you actually reach Infisical. Get it wrong and login redirects break.
- Lock the file down, then start:
chmod 600 .env
docker compose -f docker-compose.prod.yml up -d
chmod 600 stops other users on the box from reading the file. up -d starts the three containers in the background.
- Open
https://{YOUR_DOMAIN}and create the first account: it becomes the admin.
Back up your
ENCRYPTION_KEYfrom.env. Losing it means you can't decrypt secrets, even after restoring the database. It's the one value you can't regenerate.
Set it up: Kubernetes + Helm
Running a homelab or cluster? Use the Helm chart instead of Compose.
helm repo add infisical https://dl.cloudsmith.io/public/infisical/helm-charts/helm/charts/
helm install infisical infisical/infisical-standalone \
--namespace infisical --create-namespace
This deploys the same backend with bundled Postgres and Redis. Point your ingress at it and set SITE_URL the same way.
Share with your laptop
Install the CLI, then log in against your instance:
infisical login --domain https://{YOUR_DOMAIN}
This writes a token to your machine so later commands know where to talk to.
Create a project and link it to your repo folder:
cd /path/to/your/project
infisical init
infisical init creates a project (or links an existing one) and drops a small config file that remembers the project and environment.
Now import the .env you already have:
infisical secrets set --env=dev --file .env
Every line of your old .env becomes a secret in Infisical. You can delete the file.
The two commands you'll use every day:
| Command | What it does |
|---|---|
infisical run --env=dev -- npm start |
Injects secrets as env vars, runs the command |
infisical export --env=dev > .env |
Writes secrets back to a file (for tools that demand one) |
infisical run is the nice part: the secrets exist only for the life of that process. Nothing sits on disk.
Share with your server
A server shouldn't hold a .env either. Give it a machine identity instead of a user login, then let it fetch at deploy time.
┌─────────────┐
│ Infisical │ one source of truth
└──────┬──────┘
┌────────┴─────────┐
│ │
laptop (CLI) server (machine identity)
infisical run fetches secrets at deploy
In CI, you set the machine identity's credentials as secret env vars, then:
infisical run --env=prod -- ./deploy.sh
The server gets the same secrets your laptop does, without anyone pasting them.
On Kubernetes, External Secrets Operator can sync Infisical straight into native Secret objects, so your pods never see a .env file at all.
Reference
- https://infisical.com/docs/self-hosting/deployment-options/docker-compose
- https://infisical.com/docs/self-hosting/deployment-options/kubernetes-helm
- https://infisical.com/docs/cli/overview
- https://infisical.com/docs/documentation/platform/identities/overview
- https://external-secrets.io/latest/provider/infisical/
Top comments (0)