Cheatography
https://cheatography.com
Dotenvx encrypts your .env files–limiting their attack vector while retaining their benefits.
Create/List key pairs
dotenvx init |
Create .env and .env.keys in current directory |
dotenv init -p test |
Create .env.test and .env.keys for test profile |
dotenvx init -g |
Create $HOME/.env.keys for global profiles |
dotenvx keypair |
Validate and print key pair for .env |
dotenvx -p test keypair |
Validate ad print key pair for .env.test |
encrypt and decrypt for .env files
dotenvx encrypt |
Encrypt .env file |
dotenvx -p test encrypt |
Encrypt .env.test file |
dotenvx decrypt |
Decrypt .env file |
dotenvx -f decrypt |
Decrypt .env.test file |
dotenvx decrypt --stdout |
Read .env file and print the decrypted items to stdout |
.env file example
#/----[DOTENV_PUBLIC_KEY]-----------/
#/ public-key encryption for .env files /
#/ https://dotenvx.com/encryption. /
#/------------------------------------------/
DOTENV_PUBLIC_KEY="02b497...."
# .env
HELLO=encrypted:base64_text
|
.env.key file example
#/----!DOTENV_PRIVATE_KEYS------/
#/ private decryption keys. /
#/ DO NOT commit to source control /
#/ https://dotenvx.com/encryption. /
#/-----------------------------------/
DOTENV_PRIVATE_KEY=9e7018-hex-text
DOTENV_PRIVATE_KEY_EXAMPLE=a3d15-hex-text
|
GitHub Actions setup
` yaml
jobs:
dotenvx-demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: linux-china/setup-dotenvx@main
- run: npm install
- run: $HOME/.cargo/bin/dotenvx run -- node index.js
env:
DOTENV_PRIVATE_KEY: ${{ secrets.DOTENV_PRIVATE_KEY }}
`
|
Please add DOTENV_PRIVATE_KEY
secret to the Repository secrets
first.
If you use act for local GitHub Actions test, please use act -j dotenvx-demo --secret-file .env.keys
.
|
|
Get/Set item from .env file
dotenvx get admin |
Get ADMIN
value from .env file |
dotenvx get |
GET all key/value pairs from .env file |
dotenvx set admin Jackie |
SET ADMIN
to Jackie
in .env file |
dotenvx set admin - |
|
cat private.pem | dotenvx set private_key - |
Set private_key
from text of private.pem file |
Please press Ctrl+D on Linux/macOS or Ctrl+Z on Windows to finish input.
Switch profile
dotenvx -p test |
Change profile to test |
dotenvx encrypt -f .env.test |
Change profile to test by .env file name |
NODE_ENV=test dotenvx encrypt |
Change profile to test by envrionment |
profile's environment variable names: NODE_ENV, RUN_ENV, APP_ENV, SPRING_PROFILES_ACTIVE.
Rotate key pair for project
dotenvx rotate |
Rotate key pair for .env file |
dotenvx -p prod rotate |
Rotate key pair for .env.prod file |
dotenvx rotate -f .env.prod |
Rotate key pair for .env.prod file |
Run command with .env support
dotenvx -- ./demo.sh |
Inject env variables from .env and run ./demo.sh |
dotenvx -f prod -- ./demo.sh |
Inject env variables from .env.prod and run ./demo.sh |
dotenvx -- echo '$HELLO' |
Inject env variables from .env to run command line |
Please use single quote to wrap variables from .env file.
Misc
eval $(dotenvx decrypt --export) |
Export .env items to environment variables |
eval $(dotenvx get hello --format shell) |
Export HELLO from .env items as environment variable |
dotenvx ls |
List all .env file from current directory recursively |
dotenvx -f test ls |
List all .env.test file from current directory recursively |
dotenvx diff key1,key2 |
Disply keys' values between all .env files |
dotenvx diff key1,key2 --format csv |
Disply keys' values between all .env files by csv |
Tips: if you use direnv, and you can add "eval $(dotenvx decrypt --export)" to the .envrc file to automatically load .env as the environment variables when you enter the directory.
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by linux_china