Secure .env File Management Made Simple
A lightweight Rust tool for securely compressing, encoding, and managing .env files in your projects
- Features
- Why compress-env?
- Quick Start
- Installation
- Uninstallation
- Usage
- How it Works
- Security
- Tips
- License
- Contributing
- Contact & Support
Managing environment variables across different development environments, staging servers, and production deployments can be challenging. compress-env solves this problem by:
- Simplifying backup and restoration of .env files with a single command
- Enhancing security with optional password-based encryption
- Preserving directory structures when working with complex projects
- Reducing the risk of exposing sensitive credentials in your version control system
- Working seamlessly across different operating systems
Whether you're a solo developer or part of a team, compress-env helps you manage your environment variables efficiently and securely.
# Install compress-env
curl -L https://github.com/cavaldos/compress-env/releases/download/v0.1.1/compress-env -o compress-env
# Compress all .env files in your project
./compress-env compress
# Restore your .env files
./compress-env restore- Secure Encoding: Compress and encode .env files with optional password protection
- Directory Structure Preservation: Maintains the original directory structure when restoring
- Selective Compression: Compress specific .env files or all .env files in a directory tree
- Simple Restoration: Easily restore .env files to their original locations
- Password Protection: Add an extra layer of security with password-based encryption
-
Download the pre-built binary from the Release page or use curl:
For Linux/macOS:
# Download the latest release curl -L https://github.com/cavaldos/compress-env/releases/download/v0.1.1/compress-env -o compress-env # Or specify a version (replace v0.1.1 with the desired version) # curl -L https://github.com/cavaldos/compress-env/releases/download/v0.1.0/compress-env -o compress-env
For Windows (using PowerShell):
# Download the latest release curl.exe -L https://github.com/cavaldos/compress-env/releases/download/v0.1.0/compress-env.exe -o compress-env.exe # Or specify a version (replace v0.1.1 with the desired version) # curl.exe -L https://github.com/cavaldos/compress-env/releases/download/v0.1.1/compress-env.exe -o compress-env.exe
-
Make the binary executable:
chmod +x compress-env
-
Move the binary to a directory in your system PATH:
For Linux/macOS:
# Move to /usr/local/bin (requires sudo) sudo mv compress-env /usr/local/bin/ # Or move to ~/.local/bin (doesn't require sudo) mkdir -p ~/.local/bin mv compress-env ~/.local/bin/ # Make sure ~/.local/bin is in your PATH echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # Or if you use zsh echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
For Windows:
# Create a directory for binaries if it doesn't exist mkdir -p $env:USERPROFILE\bin # Move the binary move compress-env.exe $env:USERPROFILE\bin\ # Add to PATH (run in PowerShell as Administrator) [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$env:USERPROFILE\bin", "User")
-
Verify the installation:
compress-env --version
-
Clone the repository:
git clone https://github.com/cavaldos/compress-env.git cd compress-env -
Build the release version:
cargo build --release
-
Move the binary to a directory in your system PATH:
For Linux/macOS:
# Move to /usr/local/bin (requires sudo) sudo cp target/release/compress-env /usr/local/bin/ # Or move to ~/.local/bin (doesn't require sudo) mkdir -p ~/.local/bin cp target/release/compress-env ~/.local/bin/
For Windows:
# Create a directory for binaries if it doesn't exist mkdir -p $env:USERPROFILE\bin # Copy the binary copy target\release\compress-env.exe $env:USERPROFILE\bin\ # Add to PATH (run in PowerShell as Administrator) [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$env:USERPROFILE\bin", "User")
-
Verify the installation:
compress-env --version
-
If you installed the binary to
/usr/local/bin:sudo rm /usr/local/bin/compress-env
-
If you installed the binary to
~/.local/bin:rm ~/.local/bin/compress-env
-
If you installed the binary to your user bin directory:
# Remove the binary Remove-Item $env:USERPROFILE\bin\compress-env.exe
-
Verify the uninstallation:
compress-env --version
If the uninstallation was successful, you should see a "command not found" error.
Usage: compress-env [COMMAND] [OPTIONS]
Commands:
compress - Compress and encode all .env files into a single encrypted binary file
restore - Decode and restore .env files from the encrypted binary file
Options:
-o <filename> - Specify the output filename for compression (default: .env.bin)
-i <filename> - Specify the input filename for restoration (default: .env.bin)
-f <file1> <file2> ... - Specify specific .env files to compress
-p <password> - Specify a password for encryption/decryption (optional)
-h, --help - Show this help message
-v, --version - Show version information# Compress all .env files in the current directory tree
compress-env compress
# Compress all .env files with a custom output filename
compress-env compress -o secrets.bin
# Compress specific .env files with password protection
compress-env compress -f ./project1/.env ./project2/.env -o project-secrets.bin -p mypassword
# Restore .env files from the default backup file (.env.bin)
compress-env restore
# Restore .env files from a custom backup file with password
compress-env restore -i secrets.bin -p mypassword- Searches for all .env files in your current directory and subdirectories (or uses specified files)
- Aggregates the contents with path information into a single data structure
- Applies encoding (with optional password-based encryption)
- Stores the encoded data in a binary file (default:
.env.bin)
- Reads the encoded binary file
- Decodes the content (using the provided password if encrypted)
- Parses the file paths and contents
- Recreates each .env file in its original location with its original content
When using the password option (-p), compress-env applies a simple but effective encryption to your environment variables. This adds an extra layer of protection for sensitive information like API keys, database credentials, and other secrets.
You can use compress-env to manage different environment configurations:
# Save production environment variables
compress-env compress -o prod.env.bin -p production-password
# Save development environment variables
compress-env compress -o dev.env.bin -p development-password
# Restore the appropriate environment as needed
compress-env restore -i prod.env.bin -p production-passwordAdd compress-env to your deployment workflow to automatically backup environment variables:
# In your deployment script
compress-env compress -o backup-$(date +%Y%m%d).env.bin -p "$BACKUP_PASSWORD"This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- GitHub: github.com/cavaldos/compress-env
- Author: Nguyễn Ngọc Khánh
- Report Issues: Submit an Issue
- Feature Requests: Submit a Feature Request
If you find compress-env useful, please consider giving it a star on GitHub! It helps make the project more visible and encourages continued development.