![](/img/trans.png)
[英]How can I store Github token with Git Credential Manager on Ubuntu?
[英]How to use Git credential store on WSL (Ubuntu on Windows)?
我尝试按照以下说明操作: https : //stackoverflow.com/a/40312117/21728基本上是这样做的:
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
但是当我做任何网络操作时,我得到这个错误:
** (process:7902): CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY
我猜这是合乎逻辑的,因为确实没有 X11 显示器。
如何使 Git 凭据缓存在 Windows (WSL) 上的 Ubuntu 上工作?
如果您为 Windows 安装了 Git,则您的系统上会安装一个 Windows 集成凭据管理器。
您可以从WSL如发现运行Windows可执行文件在这里。
要使用它,您可以运行以下命令(假设您的 git for windows 安装在 C:\\Program Files\\Git 上)
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"
我已经创建了一个脚本来为你做这件事。 我将它与我的 Chef 编排一起使用。
cmd.exe
并调用where git-credential-manager.exe
cmd.exe
调用where git.exe
C:\\Program Files\\Git\\cmd\\git.exe
C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-credential-manager.exe
where
获取路径。我们需要:
/mnt/c/
替换C:\\
\\
翻转到/
\\\\
转义空格(和括号,如果有的话)所以...
"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-credential-manager.exe"
变成..."/mnt/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
我上面的脚本有一个功能可以做到这一点
dos_path_to_linux(){
sed -e 's?\\?/?g' -e' s?[cC]:?/mnt/c?' <<<"$1"
}
但是,正如@12345ieee 此后评论的那样,一个wslpath
实用程序已添加到WSL 版本 17046 中。 值得一试,但我目前无法访问 Windows 进行验证。 (请注意,即使在我的链接的发行说明中给出了使用说明,但该命令目前似乎不包含使用说明、-h 等)
bash
调用git config --global credential.helper "<converted/path>"
使用 Windows 10 和“WSL”,我创建了一个 ~/.gitconfig 文件,但将 [credential] 部分标签错误地输入为 [credentials]。 我尝试运行 git credential fill 然后将其输出提供给 git credential批准,这可能有效,但我怀疑不是因为它说“用法:git credential [fill|approve|reject]”。 最后,我只是跑了:
$ git config --global credential.helper cache
然后做了一个git pull; 当提示输入用户名和密码时,我像往常一样输入它们。 在那之后,它记住了它。 我发现它已将(正确命名的)部分添加到我的 ~/.gitconfig 中:
[credential]
helper = cache
我编辑了它以提供更长的超时时间:
[credential]
helper = cache --timeout=144000
现在这一切似乎都运行良好。
alias git=git.exe
将简单地使用 windows 中的 git.exe 及其配置
到目前为止,所有答案都过于复杂。 而且 git 文档并没有真正的帮助,他们喜欢参考资料很多,所以你需要按照 2-3 个链接来获取你需要的信息!
git.exe
与 WSL 一起使用! 使用 linux git sudo apt install git-all
(我认为它预装了 Ubuntu)。git 默认支持 2 种方法。 要查看您安装了哪些方法,请执行以下命令:
git help -a | grep credential
我的结果是:
credential Retrieve and store user credentials
credential-cache Helper to temporarily store passwords in memory
credential-store Helper to store credentials on disk
@selkieTG 在他们的回答中涵盖了这一点,包括完整性......
git config --global credential.helper "cache --timeout 30000"
将您的密码/令牌缓存 30,000 秒(8 小时 20 分钟)
git config --global credential.helper "store"
将纯文本密码/令牌存储在~/.git-credentials
。
纯文本?! 对于 WSL,我完全可以在这里使用纯文本。 我输入凭据以运行我的 Windows 计算机,然后输入凭据以登录 WSL2。 我需要隐藏这些吗? 不是真的,它在我的开发箱上更方便。
如果你真的想使用manager-core
你可以在你的Ubuntu 版本中安装它。 然后使用它。
我最近刚刚更新到 WSL2,在我的情况下,以下内容不起作用:
"/mnt/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
有效的是以下内容: git config --global credential.helper "/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
在我从路径中删除/mnt/
,我收到了“未找到”错误。
根据我的调查,在干净的 Windows 启动后,在 WSL2 中安装 Windows 驱动器存在问题,更多详细信息请点击此处: https://github.com/microsoft/WSL/issues/4122
: https://github.com/microsoft/WSL/issues/4122
在我的情况下,这是最可能的原因.
另一个原因可能是/etc/wsl.conf
中根目录的错误配置
无法在 WSL2 和 Debian 上使用git-credential-manager.exe
进行此操作。 我总是得到remote: Repository not found.
没有进一步的错误。
相反,我对git-credential-manager-core.exe
做了同样git-credential-manager-core.exe
所以我的配置现在是credential.helper=/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe
。 这立即奏效,事先在 Windows 上设置了 GitHub 2FA/PAT。
我有以下 git 版本:
下载:(gcmcore-linux_amd64.2.0.567.18224.deb) https://github.com/GitCredentialManager/git-credential-manager/releases/tag/v2.0.567
安装:
sudo apt install gcmcore -y 或
须藤 dpkg -i <path-to-package.deb> (gcmcore-linux_amd64.2.0.567.18224.deb)
配置:
导出 DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
git-credential-manager-core 配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.