Use master.key in Rails 5.2

Using master.key has been recomemded since rails 5.2.
We need the master.key to deploy for provisioning environment.

master.key is written in .gitignore.
So, I need to create it by following command in my development environment.

rails credentials:edit

If you don’t set editor, following messages are showed.

No $EDITOR to open file in. Assign one like this:

EDITOR="mate --wait" bin/rails credentials:edit

For editors that fork and exit immediately, it's important to pass a wait flag,
otherwise the credentials will be saved immediately with no chance to edit.

So I did the command like this:

$ EDITOR="vi" bin/rails credentials:edit
Adding config/master.key to store the master encryption key: 0dc37813ecc2d68f6a4847d50e6d8384

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/master.key

Ignoring config/master.key so it won't end up in Git history:

      append  .gitignore

And I set the editor to vi.

$ echo 'export EDITOR="vi"' >> ~/.bash_profile
$ source ~/.bash_profile

As I dit ‘EDITOR=”vi” bin/rails credentials:edit’, then config/master.key was created.

At last, I created config/master.key in my provisioning environment.
And I copied the file’s value in my development environment to the provisioning environment file.

Refenrece: https://qiita.com/jnchito/items/3884f9a2ccc057f8f3a3

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です