gpt4 book ai didi

git - 在哪里存储我的 Git 个人访问 token ?

转载 作者:IT王子 更新时间:2023-10-29 01:03:14 30 4
gpt4 key购买 nike

在 GitHub 中生成个人访问 token 后,是否需要将其存储在机器本地的某个位置?

如果是,是否有任何首选的存储方式?

最佳答案

Half the point of passwords is that (ideally) you memorize them and the system hashes them, so therefore they're never stored anywhere in plain text.
Yet GitHub's personal access token system seems to basically force you to store the token in plain text?

首先,一个 PAT (Personal Access Token)不是一个简单的密码,而是一个等价物:

  • 您可以生成多个时间(例如,每台机器一次,您需要从中访问 GitHub 存储库)
  • 您可以随时撤销(从 GitHub 网络界面),这会使该 PAT 过时,即使它在其中一台机器上徘徊也是如此。

这与您的密码不同,后者对您的帐户而言是唯一的,并且不能轻易更改,而不必在您碰巧使用它的任何地方修改它。


由于在命令行或 API 上使用 Git 通过 HTTPS 执行 Git 操作时可以使用 PAT 代替密码,因此您可以使用 git credential helper安全地缓存它。
例如,在 Windows 上,将使用 the Windows Credential Manager , 通过 GCM -- Git Credential Manager -- for Windows, Mac or Linux :

git config --global credential.helper manager-core

第一次推送到存储库时, pop 窗口会要求您提供凭据:用户名您的 PAT。
下一次,它不会询问,而是直接重复使用该 PAT,它仍然安全地存储在您的凭据管理器中。

类似的想法适用于 Mac with the OSX keychain , 和带有 GNOME Keyring 的 Linux (到 2021 年,它将是 need a DBus session and libsecret ),但到 2021 年,GCM-Core 将涵盖这些用例。
这个想法仍然存在:将 PAT 存储在一个加密凭证存储中。


如上所述,更现代的解决方案(2020 年第 4 季度)是 Microsoft Git-Credential-Manager-Core

git config --global credential.helper manager-core

你需要它来安装 git-credential-manager-core,下载它的 latest release , 比如 gcmcore-linux_amd64.2.0.474.41365.deb

sudo dpkg -i <path-to-package>
git-credential-manager-core configure

虽然,在 Linux 上使用 GCM(Git-Credential-Manager-Core),如 Mekky Mayata 所述在 the comments ,你需要先定义一个git config --global credential.credentialStore

参见“Credential stores on Linux”:

There are four options for storing credentials that Git Credential Manager (GCM) manages on Linux platforms:

By default, GCM comes not configured.
You can select which credential store to use by setting the GCM_CREDENTIAL_STORE environment variable, or the credential.credentialStore Git configuration setting.

agent18 所述在 the comments , 在安装 libsecret-1-0libsecret-1-dev 之后使用 git-credential-libsecret 是很好的第一步。
但是,同样,它现在应该由 credential-manager-core 包装。

关于git - 在哪里存储我的 Git 个人访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46645843/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com