使用 Git 存储密码有多安全?

How secure is storing password with Git?

我在工作场所使用 Git,公司政策不允许我以不安全的方式存储密码。有没有比使用 git config credential.helper store 将密码存储到 Git 服务器更好的选择?

P.S。不能使用密钥验证,因为它在我们的服务器上不允许。

git config credential.helper store 不是很安全;正如documentation中所说:

Using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions

The ~/.git-credentials file will have its filesystem permissions set to prevent other users on the system from reading it, but will not be encrypted or otherwise protected.

因此它会按原样存储您的密码。 Git 允许将您的钥匙串 git config --global credential.helper osxkeychain 用于 OSX,因此它似乎更安全。对于 Linux 系统,您可以使用 git config credential.helper cache,它将密码存储在您的内存中。或者您可以按照 git help credentials:

中的说明自己编写

You can write your own custom helpers to interface with any system in which you keep credentials. See the documentation for Git's credentials API for details

此外,@VonC 指出了关于.netrc 文件的跨平台GPG-based solution. See also this question

Linux还有gnome-keyring helper(感谢@jazakmeister 的建议)