How to store API keys and .env files securely on a Mac
By the Coffer team · Updated
Short answer: never commit keys to git, keep a .env.example with fake values in the repo, rotate any key that leaks, and keep your own backup copy of keys in an encrypted place rather than a plain text file, a notes app or a chat. Coffer is an encrypted vault on your Mac made for exactly that.
Habits that prevent most leaks
- Add
.envto.gitignorebefore your first commit. Commit a.env.examplewith placeholder values instead. - Use separate keys per project and per environment, with the least access each needs, so one leak is small.
- Rotate on suspicion. If a key reaches a public repo, a screenshot or a chat, revoke it at the provider. Deleting the commit is not enough.
- Don't paste keys into notes, tickets or chat. They stay in history and search.
- Set expiry where the provider allows and track the date.
Where a plain .env file ends up
A .env file is plain text. Copies of it can end up in Time Machine and other backups, in iCloud Drive or Dropbox folders if the project lives in one, in editor history and in shell history if you paste values into Terminal. None of that is encrypted for you.
Team tools vs. your own copy
For running production and sharing with a team, use a proper secrets manager or your cloud provider's secret store, so access can be controlled and audited. That is a different job from keeping your own private copy: the keys you would need if your laptop died, the SSH key for your server, the recovery codes for your accounts.
Keep your own copy in Coffer
- Open Coffer and unlock with Touch ID or your passphrase.
- Add a secret: give it a name such as
OPENAI_API_KEY, choose a category (API key, SSH key, .env, crypto, password) and paste the value. You can also import a whole.envfile as a file. - Set an expiry date if the key has one, and Coffer reminds you.
- When you need it, copy it. The clipboard is cleared after a short time.
- Lock with ⌘⇧L when you step away. The vault stays on your Mac, encrypted, with no account.
It also keeps passports, photos and documents, so one vault covers both your keys and your private files. Try it free for 7 days.
Frequently asked questions
Where should I store API keys on my Mac?
Keep the live keys in your project's untracked .env file or your secrets manager, and keep a private encrypted copy somewhere you control, such as an encrypted vault, so you can recover them if a machine dies.
Is it safe to keep a .env file on my laptop?
It is common practice, but the file is plain text. It is copied into backups and any synced folders, and it is exposed if the Mac is compromised. Keep it out of git, out of synced folders when you can, and keep only the keys you need.
What should I do if I committed a key to GitHub?
Revoke or rotate the key at the provider straight away. Deleting the commit is not enough, because the key may already have been copied or scraped.
Can Coffer replace a team secrets manager?
No. Team tools such as cloud secret managers handle sharing, access control and CI. Coffer is for your own private copies on your Mac: encrypted, local, no account.
Can I get a reminder when a key expires?
Yes. In Coffer you can set an expiry date on a secret and it reminds you before it runs out.