请note,从 2021 年 8 月 13 日开始,github 在验证 Git 操作时将不再接受帐户密码,并将要求对 GitHub 上所有经过验证的 Git 操作使用基于令牌的身份验证.com。您也可以继续使用您喜欢的 SSH 密钥。
因此,您必须使用给定身份验证上下文的用户名静态配置(使用 github 时):
https://username:<personal-access-tokens>@repository-url.com
请注意,我们使用的是<personal-access-tokens>,而不是<password>
有关如何创建个人访问令牌的更多详细信息,请查看documentation。
github documentation 说:
GitHub over HTTPS...每次使用 Git 进行身份验证时
GitHub,系统会提示您输入凭据以进行身份验证
使用 GitHub,除非您使用 credential helper 缓存它们。
...
使用 SSH ... 每次使用 Git 向 GitHub 进行身份验证时,
系统会提示您输入 SSH 密钥密码,除非您已经
stored the key.
github recommends 通过 HTTPS 连接。可能是因为他们want you to useGit Credential Manager Core。但是Git Credential Manager Core 在 Windows 和 macOS 上运行。 Linux 支持(截至发布时间)处于早期预览。
所以,我只会给出 Git 和 SSH 的解决方案。
Git 的 documentation 讨论如何避免使用 gitcredentials 一遍又一遍地输入相同的凭据。
解决方案 1
使用凭证助手缓存密码(在内存中短时间)。
git config --global credential.helper cache
解决方案 2
使用凭证助手存储密码(无限期地存储在磁盘上)。
git config --global credential.helper 'store --file ~/.my-credentials'
您可以在documentation 中找到凭据的保存位置(如果未使用 --file 明确设置)。
注意:
为了解决 gitcredentials 存储的凭据完全未加密(“原样”)的concern,您始终可以在使用前加密文件并解密。
解决方案 3
这几乎是来自Generating a new SSH key and adding it to the ssh-agent 的直接复制粘贴。我认为跟随链接会比从这里阅读更好。无论如何,我将在这里复制粘贴命令。
-
使用ssh-keygen -t ed25519 -C "your_email@example.com" 创建 ssh 密钥。您还可以使用 RSA 代替 Ed25519,使用 ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-
Add the SSH key to your account on GitHub.
-
如果没有启动,使用$ eval "$(ssh-agent -s)"在后台启动ssh-agent
-
使用$ ssh-add ~/.ssh/id_ed25519 将您的 SSH 私钥添加到 ssh-agent。如果您使用不同的名称创建了密钥,或者如果您要添加具有不同名称的现有密钥,请将命令中的 id_ed25519 替换为您的私钥文件的名称。