First Secret
Store an encrypted secret in your vault and configure a shell plugin to automatically load it when you enter a project directory.
Prerequisites
Section titled “Prerequisites”- dotsecenv installed (Installation)
- GPG key available
- Basic setup complete (Getting Started)
-
Verify your setup
Make sure you’re logged in:
Terminal window dotsecenv vault describeYou should see your identity listed. If not, complete the Getting Started guide first.
-
Store a secret
Let’s store a database password:
Terminal window echo "super-secret-db-password" | dotsecenv secret put DATABASE_PASSWORDVerify it was stored:
Terminal window dotsecenv secret get DATABASE_PASSWORD# Output: super-secret-db-password -
Store a namespaced secret
Use namespaces to organize secrets by environment:
Terminal window echo "prod-password" | dotsecenv secret put prod::DATABASE_PASSWORDecho "staging-password" | dotsecenv secret put staging::DATABASE_PASSWORDList all secrets:
Terminal window dotsecenv vault describe -
Install the shell plugin
Add to
~/.bashrc:Terminal window # dotsecenv shell plugineval "$(dotsecenv completion bash)"# Auto-load .secenv files_dotsecenv_hook() {if [[ -f .secenv ]]; theneval "$(dotsecenv env load)"fi}if ! [[ "${PROMPT_COMMAND:-}" =~ _dotsecenv_hook ]]; thenPROMPT_COMMAND="_dotsecenv_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"fiAdd to
~/.zshrc:Terminal window # dotsecenv shell plugineval "$(dotsecenv completion zsh)"# Auto-load .secenv filesautoload -U add-zsh-hook_dotsecenv_hook() {if [[ -f .secenv ]]; theneval "$(dotsecenv env load)"fi}add-zsh-hook chpwd _dotsecenv_hookAdd to
~/.config/fish/config.fish:Terminal window # dotsecenv completionsdotsecenv completion fish | source# Auto-load .secenv filesfunction _dotsecenv_hook --on-variable PWDif test -f .secenvdotsecenv env load | sourceendendReload your shell:
Terminal window source ~/.bashrc # or ~/.zshrc -
Create a
.secenvfileIn your project directory, create a
.secenvfile:Terminal window cd ~/my-projectcat > .secenv << 'EOF'# Secrets loaded from dotsecenv vaultDATABASE_PASSWORD={dotsecenv}API_KEY={dotsecenv/prod::API_KEY}EOFThe syntax is:
VAR={dotsecenv}— Load secret with same name as variableVAR={dotsecenv/SECRET_NAME}— Load specific secret into variableVAR={dotsecenv/namespace::SECRET_NAME}— Load namespaced secret
-
Test automatic loading
Leave and re-enter the directory:
Terminal window cd ~cd ~/my-project# You may see a prompt: "Load secrets? [y]es / [n]o / [a]lways"# Type 'y' or 'a'echo $DATABASE_PASSWORD# Output: super-secret-db-password
Expected Result
Section titled “Expected Result”- Secrets stored encrypted in your vault
- When you
cdinto a directory with.secenv, secrets auto-load - When you leave the directory, secrets are unloaded (environment cleared)
cd ~/my-projectecho $DATABASE_PASSWORD# super-secret-db-password
cd ~echo $DATABASE_PASSWORD# (empty)Variations
Section titled “Variations”Using with .env files
Section titled “Using with .env files”You can use both .env and .secenv together:
# .env - Non-sensitive configurationDATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_NAME=myapp
# .secenv - Sensitive secretsDATABASE_PASSWORD={dotsecenv}Interactive secret input
Section titled “Interactive secret input”For sensitive secrets, avoid piping to prevent history leaks:
dotsecenv secret put API_KEY# Type or paste your secret, then Ctrl+DReading from files
Section titled “Reading from files”cat ~/.ssh/private_key | dotsecenv secret put SSH_PRIVATE_KEYMultiple vaults
Section titled “Multiple vaults”Store secrets in a project-specific vault:
dotsecenv init vault -v ./secrets/vaultecho "local-secret" | dotsecenv secret put -v ./secrets/vault LOCAL_SECRETTroubleshooting
Section titled “Troubleshooting”Secret not loading?
- Check the
.secenvsyntax - Ensure the secret exists:
dotsecenv vault describe - Verify you’re logged in:
dotsecenv vault describeshould show your identity
Wrong secret value?
Secrets are versioned. Get the latest:
dotsecenv secret get --last DATABASE_PASSWORDNext Steps
Section titled “Next Steps”- Share a Secret — Share secrets with teammates
- Revoke Access — Remove someone’s access to secrets