如何在WSL(Windows上的Ubuntu)上使用Git凭据库?
我试着遵循以下说明:基本上是这样做的:如何在WSL(Windows上的Ubuntu)上使用Git凭据库?,git,ubuntu,windows-subsystem-for-linux,Git,Ubuntu,Windows Subsystem For Linux,我试着遵循以下说明:基本上是这样做的: 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 但当我进行任
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上的Ubuntu(WSL)上工作?如果您安装了Git for Windows,则系统上安装了Windows集成凭据管理器 您可以从找到的WSL运行windows可执行文件 要使用它,您可以运行以下命令(假设您的git for windows安装在C:\Program Files\git上) 使用Windows 10和“WSL”,我创建了一个~/.gitconfig文件,但将[credential]部分标签误输入为[credentials]。 我尝试运行git-credential-fill,然后将其输出提供给git-credential-approve,这可能会起作用,但我怀疑不会,因为它说“用法:git-credential[fill | approve | reject]”。 最后,我简单地说:
$ git config --global credential.helper cache
然后做了一个git拉;当提示输入用户和密码时,我照常输入。在那之后,它想起了它。我发现它已将(正确命名)部分添加到我的~/.gitconfig中:
[credential]
helper = cache
我对其进行了编辑,以提供更长的超时时间:
[credential]
helper = cache --timeout=144000
现在一切似乎都很顺利。TL;博士
我创造了。我用它来配合我的厨师编排
找到或安装git-credential-manager.exe
cmd.exe
并调用where-git-credential-manager.exe
- 如果它返回一条路径,很好。继续转换路径
- 如果不是
cmd.exe
中调用where git.exe
- 如果没有返回路径,下一步是单独安装凭据管理器
- 如果它确实返回一个路径,它将类似于:
C:\ProgramFiles\Git\cmd\Git.exe
- 让我们删除下一个到最后一个斜杠后的所有内容,并将其更改为:
C:\ProgramFiles\Git\mingw64\libexec\Git core\Git credential manager.exe
- 如果存在,那就太好了。继续转换路径
- 否则
where
获取路径C:\
替换为/mnt/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\u路径到\u linux(){
sed-e's?\\?/?g'-e's?[cC]:?/mnt/c?我最近刚刚更新到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
这是我最可能的原因
另一个原因可能是/etc/wsl.conf
alias git=git.exe
将简单使用windows中的git.exe及其配置无法在使用Debian的WSL2上使用git credential manager.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版本:
- 窗口:
git版本2.31.0.windows.1
适用于Windows v1.20.0.0的Git凭据管理器
- Debian/WSL2
git版本2.30.2
所有的答案到这一点都过于复杂。而且git文档并没有真正的帮助,他们非常喜欢参考资料,所以你需要通过2-3个链接来获得你需要的信息
您不需要在WSL中使用Windowsgit.exe
!使用linux gitsudo 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"
将缓存您的密码/令牌30000秒(8小时20分钟)
将在~/.git凭据中存储纯文本密码/令牌
纯文本?!!对于WSL,我完全可以在这里使用纯文本。我输入运行Windows计算机的凭据,我输入登录WSL2的凭据。我需要隐藏这些吗?不需要,这在我的开发框中更方便
如果你真的想使用manager core
,你可以将它安装在你的.中,然后使用它。好的,你不能安装,但是你可以使用WSL中的windows可执行文件,这样你就可以使用在WSL上运行的git for windows on git中的凭据帮助程序。这个配置是从我自己的机器上复制的。git config--global credential.hel根据“/mnt/c/Program\Files/Git/mingw64/libexec/Git core/Git credential wincred.exe”
这是我使用的命令。如果您有sp的路径
git config --global credential.helper "cache --timeout 30000"
git config --global credential.helper "store"