Migrate from .env
Take an existing .env file, move the sensitive values into your dotsecenv vault, and set up .secenv so everything still loads automatically.
Prerequisites
Section titled “Prerequisites”- Getting Started completed
-
Start with your
.envfileA typical project
.envlooks like this:.env DATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_NAME=myappDATABASE_PASSWORD=super-secret-passwordAPI_KEY=sk-live-abc123xyzThree of these are non-sensitive configuration. Two are secrets you would not want in a public repo.
-
Identify the secrets
Ask yourself: would I panic if this value appeared on a public GitHub repo? If yes, it belongs in the vault.
In this example:
DATABASE_PASSWORDandAPI_KEY. -
Store the secrets in your vault
Terminal window echo "super-secret-password" | dotsecenv secret store DATABASE_PASSWORDecho "sk-live-abc123xyz" | dotsecenv secret store API_KEY -
Create a
.secenvfileTerminal window cat > .secenv << 'EOF'DATABASE_PASSWORD={dotsecenv}API_KEY={dotsecenv}EOFThe
{dotsecenv}syntax tells the shell plugin to fetch the secret with the same name as the variable. -
Remove the secrets from
.envYour
.envnow contains only non-sensitive values:.env DATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_NAME=myapp -
Verify everything loads
Terminal window cd ~cd ~/my-project# dotsecenv: loaded 2 secret(s) from .secenv: DATABASE_PASSWORD, API_KEYecho $DATABASE_HOST# Output: localhostecho $DATABASE_PASSWORD# Output: super-secret-passwordecho $API_KEY# Output: sk-live-abc123xyzAll five variables are available. Only three are on disk in plaintext.
-
Update version control
Terminal window echo ".env" >> .gitignoregit add .secenv .gitignoregit commit -m "chore: move secrets to dotsecenv vault"
Expected result
Section titled “Expected result”| Variable | Source | On disk in plaintext? |
|---|---|---|
DATABASE_HOST | .env | Yes |
DATABASE_PORT | .env | Yes |
DATABASE_NAME | .env | Yes |
DATABASE_PASSWORD | vault via .secenv | No |
API_KEY | vault via .secenv | No |
Next steps
Section titled “Next steps”- Reloading Secrets — what to do when you rotate a secret
- Share a Secret — share the encrypted secrets with teammates