Back to blog
Developer Security
6 min

How to Safely Share .env Files and Environment Variables with Your Team

Stop sending database passwords and API keys over Slack. Here's how to securely share .env files with your development team — from quick fixes to long-term solutions.

LOCK.PUB
2026-03-04
How to Safely Share .env Files and Environment Variables with Your Team

How to Safely Share .env Files and Environment Variables with Your Team

The Onboarding Moment We All Dread

A new developer joins the team. They're setting up their local environment and they ask the inevitable question:

"Hey, can someone send me the .env file?"

What happens next is depressingly predictable. A senior dev copies the entire contents of their .env file — database passwords, API keys, third-party secrets — and drops it into a Slack DM or iMessage thread. That message now lives on a server somewhere, searchable, forever.

We've all done it. And it's a much bigger risk than most teams realize.

Why .env Files Are Dangerous to Share Insecurely

Your .env file is essentially a treasure chest of credentials:

  • Database connection strings — host, port, username, password, database name
  • API keys — Stripe, AWS, Firebase, and other services that cost real money if abused
  • Third-party secrets — OAuth client secrets, webhook signing keys, encryption keys
  • Internal service tokens — microservice-to-microservice authentication

When you paste these into Slack or Messenger, that data is stored on their servers. Anyone with workspace access can search for and find those messages months or years later. And if a device gets lost or compromised, those credentials go with it.

Common (Dangerous) Ways Teams Share .env Files

Method Why It's Risky
Slack / Teams DM Stored on servers permanently, searchable by workspace members
Email attachment Sits in mail servers, can be forwarded, rarely encrypted at rest
Google Docs Link leaks = anyone can access, revision history preserves content
Committed to git Even deleted commits live in git log history, bots scan GitHub in seconds
Notion / Confluence Searchable by entire workspace, no expiration

The git commit scenario is especially brutal. Automated bots continuously scan public GitHub repositories for exposed credentials. If you push a .env file by accident, your AWS keys can be compromised within minutes.

Safe Ways to Share .env Files

1. Secrets Managers

Doppler, HashiCorp Vault, and AWS Secrets Manager are purpose-built for this. They centralize your environment variables, provide fine-grained access control, audit logs, and automatic rotation. If your team has more than a handful of developers, this is the gold standard.

2. Team Password Managers

1Password Teams and Bitwarden Organization both support shared vaults where you can store .env contents as secure notes. Access is controlled per-user, and everything is end-to-end encrypted.

3. Password-Protected Self-Destructing Memos

For quick, one-time sharing — like onboarding a new developer — a tool like LOCK.PUB works well. Paste your .env contents into a secret memo, set a password and an expiration time, then share the link over Slack and the password via a separate channel (like iMessage or a phone call). Once it expires, the content is gone — no permanent record.

4. GPG-Encrypted Files

For security-conscious teams, you can encrypt the .env file with GPG before sharing it. The downside is that every team member needs to manage GPG keys, which adds friction.

Best Practices for .env Management

  1. Add .env to .gitignore immediately — This should be the first thing you do when creating a new project.
  2. Maintain a .env.example file — Include every variable with placeholder values so new developers know what's needed.
  3. Use different credentials per environment — Dev, staging, and production should never share the same keys.
  4. Rotate secrets regularly — At minimum, rotate keys quarterly.
  5. Revoke access when people leave — When a team member departs, rotate every secret they had access to. Not just their account — the actual credentials.

Quick Setup: .gitignore + .env.example

Add this to your .gitignore right now:

# Environment variables
.env
.env.local
.env.*.local

Then create a .env.example that serves as documentation:

# .env.example
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxx
FIREBASE_API_KEY=your_firebase_api_key_here
NEXT_PUBLIC_BASE_URL=http://localhost:3000

Commit this file to your repo. It tells every new developer exactly what variables they need without exposing any real values.

Stop Sending Secrets in Plain Text

Sharing .env files might seem like a minor workflow detail, but it's one of the most common sources of credential leaks. Whether you invest in a full secrets manager or use LOCK.PUB to share credentials with an expiration date, the important thing is to break the habit of pasting secrets into chat messages.

Try this right now: search your Slack workspace for DATABASE_URL or API_KEY. The results might surprise you.

Keywords

share .env file securely
share environment variables team
developer secrets management

Create your password-protected link now

Create password-protected links, secret memos, and encrypted chats for free.

Get Started Free

Create your password-protected link now

Create password-protected links, secret memos, and encrypted chats for free.

Get Started Free
How to Safely Share .env Files and Environment Variables with Your Team | LOCK.PUB Blog