Git http - 安全地记住凭据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6191985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:03:19  来源:igfitidea点击:

Git http - securely remember credentials

gitauthentication

提问by Johan Sj?berg

Is there a way to securely let git remember my credentials when connecting to remote repositories over HTTP(S)?

在通过 HTTP(S) 连接到远程存储库时,有没有办法安全地让 git 记住我的凭据?

I've tried the core.askpassapproach detailed in git-configto let an external script supply my credentials. Although it works great the username and password is still stored in plain text in the small shell script.

我已经尝试了让外部脚本提供我的凭据中core.askpass详述的方法git-config。尽管它工作得很好,但用户名和密码仍然以纯文本形式存储在小 shell 脚本中。

采纳答案by Eddie

gitinvokes cURL when running over HTTP. You can store secure credentials by setting up a .netrcfile in your user's home directory, and making it private to the user (0600 in Linux).

git通过 HTTP 运行时调用 cURL。您可以通过.netrc在用户的主目录中设置一个文件并将其设为用户私有(Linux 中的 0600)来存储安全凭证。

The contents of the file provide the username and password per remote domain.

该文件的内容提供每个远程域的用户名和密码。

machine myRemoteServer
login myUserName
password s3cret

See https://stackoverflow.com/questions/3947530/git-push-fatal-failed/7177690#7177690for full server side configuration, which can easily include calls to your ldap server.

有关 完整的服务器端配置,请参阅https://stackoverflow.com/questions/3947530/git-push-fatal-failed/7177690#7177690,其中可以轻松包含对 ldap 服务器的调用。

回答by Jakub Nar?bski

Since (I think) git version 1.7.8, from 2 December 20111), git supports so called credentials helpers.

由于(我认为)git 版本 1.7.8,从 2011 年 12 月 2 日1) 开始,git 支持所谓的凭证助手

See gitcredentials(7)manpage for details
(This manpage also decribes where core.askpassfits into this).

有关详细信息,请参阅gitcredentials(7)联机帮助页
(此联机帮助页还描述了core.askpass适合于此的位置)。

The default git installation includes two helpers:

默认的 git 安装包括两个助手:

  • cache: See git-credential-cache(1)for details.

    Cache credentials in memory for a short period of time. The stored credentials never touch the disk, and are forgotten after a configurable timeout. Note that it is Unix-only solution, as it uses socket to communicate with daemon.

  • store: See git-credential-store(1)for details.

    Store credentials indefinitely on disk. The 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. The same security as .netrcsolution in Eddie response

  • 缓存:有关详细信息,请参阅git-credential-cache(1)

    在内存中缓存凭据一小段时间。存储的凭据永远不会触及磁盘,并且会在可配置的超时后被遗忘。请注意,它是仅限 Unix 的解决方案,因为它使用套接字与守护程序进行通信。

  • store:有关详细信息,请参阅git-credential-store(1)

    将凭据无限期地存储在磁盘上。该文件将设置其文件系统权限以防止系统上的其他用户读取它,但不会被加密或以其他方式受到保护。与Eddie 响应中的.netrc解决方案相同的安全性



There are some third-party credential helpers for storing username and password in KDEWallet (KDE), in GNOME Keyring, in Windows Credential Store(this is now integrated in Git for Windows), in MacOS X Keychain, etc.

有一些第三方凭证帮助程序用于在 KDEWallet (KDE)、GNOME KeyringWindows Credential Store(现在集成在Git for Windows 中)、MacOS X Keychain 等中存储用户名和密码。



Footnotes:

脚注:

1)The Set Up GitGitHub Help page mentions that

1)成立的Git的GitHub帮助页面中提到,

You need git 1.7.10or newer to use the credential helper

您需要 git 1.7.10或更新版本才能使用凭证助手

回答by VonC

Since git 1.8.3(May, 2013), you now can specify an encrypted .netrcfor git to use:

git 1.8.3(2013 年 5 月)开始,您现在可以指定要使用的 git加密.netrc

A new read-only credential helper(in contrib/credential/netrc/) to interact with the .netrc/.authinfofiles has been added.

添加了一个新的只读凭据帮助程序(在 中contrib/credential/netrc/)以与.netrc/.authinfo文件交互。

That script would allow you to use gpg-encrypted netrc files, avoiding the issue of having your credentials stored in a plain text file.

该脚本将允许您使用 gpg 加密的 netrc 文件,避免将您的凭据存储在纯文本文件中的问题。

-f|--file AUTHFILE
specify netrc-style files.  

Files with the .gpgextension will be decrypted by GPG before parsing.
Multiple -farguments are OK. They are processed in order, and the first matching entry found is returned via the credential helper protocol (see below).

When no -foption is given, .authinfo.gpg, .netrc.gpg, .authinfo, and .netrcfiles in your home directory are used in this order.

To enable this credential helper:

带有.gpg扩展名的文件将在解析前由 GPG 解密。
多个-f参数是可以的。它们按顺序处理,找到的第一个匹配条目通过凭证帮助程序协议返回(见下文)。

当没有-f给出选项,.authinfo.gpg.netrc.gpg.authinfo,和.netrc在你的主目录文件的顺序使用。

要启用此凭据帮助程序:

git config credential.helper '$shortname -f AUTHFILE1 -f AUTHFILE2'

(Note that Git will prepend "git-credential-" to the helper name and look for it in the path.)

(请注意,Git 将git-credential-在帮助程序名称前添加“ ”并在路径中查找。)



See a complete step-by-step exampleat:
"Is there a way to skip password typing when using https://github.com".

请参阅以下位置的完整分步示例
“使用时是否可以跳过密码输入https://github.com”。

回答by John

Secure option is to use regular SSH with public/private key pair.

安全选项是使用带有公钥/私钥对的常规 SSH。