Git 凭据助手不适用于 linux 的 windows 子系统

Git credential helper doesn't work on windows subsystem for linux

我在 Windows 10 上的 WSL 中使用 Ubuntu,我在 WSL 中安装了 git 并经常使用它。我有一个非常烦人的问题,我尝试缓存我的 git 集线器凭据,这样我就不必在提交时不断输入我的 username/password 但它不起作用。我遵循 github verbaitim 提供的确切说明。首先我输入:

git config --global credential.helper cache

然后我输入:

git config --global credential.helper 'cache --timeout=2629800'

但没有任何反应,我仍然需要不断输入我的 github 用户名和密码

编辑:

澄清一下,我是通过 ubuntu wsl 上的 bash 终端执行所有这些操作的,我没有使用 git 的 windows 版本。我正在使用 ubuntu 中包含的 git 版本。我输入的所有这些命令都是 linux 命令。

可能是因为 WSL 中对 Unix 域套接字的支持不完整

您可以改用 windows 凭据管理器:https://www.edwardthomson.com/blog/git_credential_manager_with_windows_subsystem_for_linux.html

来自 link,这里是启用它的方法:

git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"

您可以使用 SSH 而不是 HTTP。设置完成后,您只需在启动 WSL 时输入 SSH 密码。

在 WSL 2 上尝试了几种方法后,这对我有用。我选择在 WSL 中托管我的 SSH 密钥,而不是 Windows。

如果您还没有按照 GitHub 的 adding a new SSH key to your GitHub account 指南进行操作。请确保 select“Linux”(对于 WSL)靠近本页顶部。

安装keychain:

sudo apt install keychain

然后将以下行添加到您的 shell 的配置文件(可能 ~/.bashrc~/.zshrc):

eval `keychain --quiet --eval --agents ssh id_rsa`

现在您只需在启动 WSL 时输入密码!

感谢 Birk Holland this article 在 Windows 和 WSL 2 之间共享 SSH 密钥。