Rails SECRET_KEY_BASE Generator
128 hex characters — bin/rails secret, without needing Ruby installed.
$ bin/rails secret
bin/rails secret, without Ruby
The whole Rails command is two lines — require "securerandom"; puts SecureRandom.hex(64) — so it emits 64 bytes as 128 lowercase hex characters. The generator above produces the identical shape in your browser, which is the point if you are in a Docker build, a CI runner or a Windows box where bin/rails secret is inconvenient. The terminal equivalent is openssl rand -hex 64; both give you the same class of secret from the same kind of CSPRNG.
Fixing "Missing secret_key_base for 'production' environment"
This is the error that sends most people here, and half the advice you will find for it is out of date. Modern Rails looks for the value in two places, in order: the SECRET_KEY_BASE environment variable, then credentials.secret_key_base in your encrypted credentials. The old config/secrets.yml that Stack Overflow answers from 2015–2018 tell you to edit is no longer read — Rails removed that support. Set SECRET_KEY_BASE to the value above in your production environment and the error clears. For asset precompilation in a build step where you have no real secret yet, set SECRET_KEY_BASE_DUMMY=1 and Rails supplies a throwaway value for that run.
Where Rails stores it, and what it protects
In development and test, Rails writes a generated value to tmp/local_secret.txt the first time it needs one, so you rarely see it. In production it is yours to manage: keep it in the environment or in credentials, out of the repository, distinct per environment. It signs and encrypts cookies, sessions and signed/encrypted message verifiers — rotating it invalidates all of those, so treat a change as a migration, not a config tweak. It is the same 64-byte hex shape as a raw hex secret, twice the length of Flask's key.
How do I generate a Rails secret_key_base without Ruby?
The Rails command is just SecureRandom.hex(64) — 64 bytes as 128 hex characters — so the terminal equivalent is openssl rand -hex 64, and the generator above produces the identical shape in your browser. Useful in Docker builds, CI or on Windows.
Missing secret_key_base for 'production' environment — how do I fix it?
Set the SECRET_KEY_BASE environment variable to a 128-hex-character value (generate one above) in your production environment. Modern Rails reads SECRET_KEY_BASE, then encrypted credentials — it no longer reads config/secrets.yml, despite what older answers say.
Where does Rails read secret_key_base from?
In order: the SECRET_KEY_BASE environment variable, then credentials.secret_key_base in encrypted credentials. In development and test it writes a generated value to tmp/local_secret.txt. Support for config/secrets.yml was removed.
What is SECRET_KEY_BASE_DUMMY?
Set SECRET_KEY_BASE_DUMMY=1 and Rails generates a throwaway secret for that process — meant for steps like asset precompilation in a Docker build where you have no real secret yet and do not want the boot to fail.
Nothing leaves your browser
- Don't take our word for it — turn off your wifi. Every generator on this site keeps working with the network disconnected. That's the whole proof, and it takes five seconds.
- Every value comes from
crypto.getRandomValues()— the CSPRNG built into your browser, neverMath.random(). - Generated secrets are never transmitted, logged or stored: no server-side generation, no cookies, no localStorage.
- Verify it yourself in the network tab: after loading, the page only talks to our self-hosted, cookie-less analytics — which counts page views and which generator type gets copied, never any value.
- Strict Content-Security-Policy; no third-party script origins.
All generators
- Base64 Secret Generator
- UUID Generator
- Password Generator
- Hex Secret Generator
- JWT Secret Generator
- Passphrase Generator
- SSH Key Generator (Ed25519)
- PIN Generator
- WireGuard Key Generator
- API Key Generator
- TOTP Secret Generator
- Django SECRET_KEY Generator
- Laravel APP_KEY Generator
- NextAuth Secret Generator
- Flask SECRET_KEY Generator
- Strapi APP_KEYS Generator
- ULID Generator
- Nano ID Generator