Infrastructure & Ops · 8 min read · Intermediate
Secrets Management & `.env` Hygiene
Keep API keys, database credentials, and private keys out of Git, client bundles, and logs.
What you'll learn
- Keep `.env`, `.jks`, and private keys strictly out of Git
- Lock down production env files with `chmod 600`
- Never expose backend secret keys in `PUBLIC_*` or `VITE_*` frontend variables
Overview
Keep API keys, database credentials, and private keys out of Git, client bundles, and logs.
Code Example
# 1. Always ignore secret files before your first commit
echo ".env" >> .gitignore
echo "*.pem" >> .gitignore
echo "*.jks" >> .gitignore
# 2. Restrict server env file permissions to root/service owner only
chmod 600 /etc/devpath-api.env
Key Takeaways
- Keep
.env,.jks, and private keys strictly out of Git - Lock down production env files with
chmod 600 - Never expose backend secret keys in
PUBLIC_*orVITE_*frontend variables
Quick Check
Check Your Understanding
Score: 0 / 1
1. You accidentally pushed an API secret key to a public GitHub repo. What must you do FIRST?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.