Cheatsheets/ Terminal

Keep Secrets Out of .zshrc

Move tokens from .zshrc into a private ~/.secrets.zsh so they never reach git, screenshots or AI transcripts

The Problem

  • If .zshrc lives in a dotfiles git repo, your next commit pushes the tokens.
  • Exported variables reach every child process, including npm postinstall scripts.
  • A raw cat ~/.zshrc in 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:

~/.zshrc
[[ -f ~/.secrets.zsh ]] && source ~/.secrets.zsh
Terminal window
umask 077; touch ~/.secrets.zsh; chmod 600 ~/.secrets.zsh

chmod 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.example with the variable names and empty values.
  • Add .secrets.zsh to .gitignore.
  • Keep each section comment next to the secrets it describes.
  • Keep non-secret config (hosts, user IDs) in .zshrc under the same heading.

Scan for Leaked Credentials

Use betterleaks to scan a file or folder for credentials. Point it at a path:

Terminal window
betterleaks dir <path> -v

Scan 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.

  1. Rotate the tokens.
  2. Put the new values in ~/.secrets.zsh.
  3. Delete any .bak copies of the old .zshrc.
  4. Delete the AI session transcript that contains them.