The Problem
- If
.zshrclives in a dotfiles git repo, your next commit pushes the tokens. - Exported variables reach every child process, including npm postinstall scripts.
- A raw
cat ~/.zshrcin an AI coding session sends every value into its transcript.
The Fix
Put the secrets in ~/.secrets.zsh with mode 600, outside the dotfiles repo, and source it:
[[ -f ~/.secrets.zsh ]] && source ~/.secrets.zshumask 077; touch ~/.secrets.zsh; chmod 600 ~/.secrets.zshchmod 600 gives the owner read and write access and everyone else nothing. New files are usually 644, which every account on the machine can read.
It protects you from: committing tokens, sharing or screenshotting .zshrc, and other user accounts.
It does not protect you from: programs you run (they run as the same user) and a stolen unencrypted disk (use FileVault).
In the Dotfiles Repo
- Add
secrets.zsh.examplewith the variable names and empty values. - Add
.secrets.zshto.gitignore. - Keep each section comment next to the secrets it describes.
- Keep non-secret config (hosts, user IDs) in
.zshrcunder the same heading.
Scan for Leaked Credentials
Use betterleaks to scan a file or folder for credentials. Point it at a path:
betterleaks dir <path> -vScan your dotfiles before you push them, or ~/.zshrc to see what is still in it. -v turns on verbose output.
If a Token Was Exposed
If a token was ever printed somewhere it should not be (a transcript, a chat, a screenshot), rotate it. Private is not the same as unexposed.
- Rotate the tokens.
- Put the new values in
~/.secrets.zsh. - Delete any
.bakcopies of the old.zshrc. - Delete the AI session transcript that contains them.