Should files involved in SSL certificate be kept confidential (added to .gitignore)?

Viewed 8381

In the process of setting up an SSL certificate for my site, several different files were created,

  • server.csr
  • server.key
  • server.pass.key
  • site_name.crt

Should these be added to .gitignore before pushing my site to github?

Apologies in advance if this is a dumb question.

2 Answers

I would like to add to @VonC 's answer, as it is in fact more complicated:

The files have different content, and depending on that they require a different access control:

  • server.csr: This is a certificate signing request file. It is generated from the key (server.key in your case) and used to create the certificate (site_name.crt in your case). This should be deleted when the certificate has been created. It should not be shared with untrusted parties.
  • server.key: This is the private key. Under no circumstances can this file be shared outside of the server. It cannot end up in a code repository. On the system it must be stored with 0600 permissions (i.e. read only) owned by either root or the web server user. At least in Linux, in Windows user access rights are handled differently, but it has to be done similarly.
  • site_name.crt: This is the signed certificate. This is considered to be public. The certificate is essentially the public key. It is sent out to everyone that connects to the server. It can be stored in the repository. (The hint from @VonC is correct, code and data should be separated, but it can be e.g. in a separate repository for the deployment).
  • server.pass.key: Don't know what this is, but it seems to contain the password to get access to the key. If this is the case the same rules as for the key apply: Never share with anyone.
Related