SSL证书涉及的文件是否应该保密(添加到.gitignore)?

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

在为我的网站设置 SSL 证书的过程中,创建了几个不同的文件,

在将我的网站推送到 github 之前,是否应该将这些添加到 .gitignore?

如果这是一个愚蠢的问题,请提前致歉。

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

它们根本不应该在 repo 中,意味着存储在 repo 之外。
这样:

  • 您不需要管理 .gitignore,
  • 您可以将这些密钥存储在安全的地方。

GitHub 在看到 users storing keys and passwords in public repositories. See the full story.

后实际上不得不在 2013 年更改它的搜索功能

The article 包括此引用:

The mistakes may reflect the overall education problem among software developers.

When you have expedited programs—"6 weeks and you'll be a real software developer"—to teach developing, security becomes an afterthought. And considering "90 percent of development is copying stuff you don't understand, I'd bet most of them simply don't know what id_rsa is"

2016年,这本“书”(开个玩笑)反映:


OP 添加:

I think Heroku requires putting the files into the repo in order to run ">heroku certs:add server.crt server.key" and setup the cert.

"Configuration and Config Vars" 是关于该主题的一个插图:

A better solution is to use environment variables, and keep the keys out of the code. On a traditional host or working locally you can set environment vars in your bashrc file. On Heroku, you use config vars.

文章“Heroku: SSL Endpoint”并不强制您在代码中包含那些密钥和证书。它们可以直接在 Heroku 上生成并保存在其他任何地方以便妥善保管。只是不在 git 仓库中。

我想补充@VonC 的答案,因为它实际上更复杂:

这些文件具有不同的内容,并且根据这些内容需要不同的访问控制:

  • server.csr:这是一个证书签名请求文件。它是从密钥(在您的情况下为server.key)生成的,并用于创建证书(在您的情况下为site_name.crt)。创建证书后应将其删除。它不应与不受信任的各方共享。
  • server.key:这是私钥。 在任何情况下 都不能在服务器外共享此文件。它不能最终出现在代码存储库中。在系统上,它必须以 root 或网络服务器用户拥有的 0600 权限(即只读)存储。至少在 Linux 中,在 Windows 中,用户访问权限的处理方式不同,但必须以类似方式完成。
  • site_name.crt:这是签名证书。这被认为是public。证书本质上是 public 密钥。它被发送给连接到服务器的每个人。它可以存储在存储库中。 (@VonC 的提示是正确的,代码和数据应该分开,但它可以例如在单独的部署存储库中)。
  • server.pass.key: 不知道这是什么,但是好像包含了获取密钥的密码。如果是这种情况,适用与密钥相同的规则:切勿与任何人共享