Decrypt Rails config credentials on a newly cloned repository
Rails uses a key to decrypt the
config/credentials.yml.enc. By default, the key is in a file
If you’ve created a rails app and pushed it to a remote repository and then cloned that same rails app on a different computer, you’ll receive the following error:
rails Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key
This could also happen if you accidentally change your
master.key since it will no longer succesfully decrypt the encrypted credential files.
If you just want to regenerate your encrypted credentials and key, you can delete
config/credentials.yml.enc and run the command:
This will regenerate both the key and the encrypted credentials file for you.
Take care because if you’ve added items to your encrypted credentials file, they will be lost.