[英]How to use Git credential store on WSL (Ubuntu on Windows)?
I've tried following these instructions: https://stackoverflow.com/a/40312117/21728 which basically do this:我尝试按照以下说明操作: 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
But when I do any network operation, I get this error:但是当我做任何网络操作时,我得到这个错误:
** (process:7902): CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY
That's logical I guess as there is indeed no X11 display.我猜这是合乎逻辑的,因为确实没有 X11 显示器。
How to make Git credentials caching work on Ubuntu on Windows (WSL)?如何使 Git 凭据缓存在 Windows (WSL) 上的 Ubuntu 上工作?
If you installed Git for Windows there is a windows integrated credential manager installed on your system.如果您为 Windows 安装了 Git,则您的系统上会安装一个 Windows 集成凭据管理器。
You can run windows executables from WSL as found here .您可以从WSL如发现运行Windows可执行文件在这里。
To use it you can run the following command (assuming that your git for windows is installed on C:\\Program Files\\Git)要使用它,您可以运行以下命令(假设您的 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"
I've created a script that does this for you .我已经创建了一个脚本来为你做这件事。 I use it with my Chef orchestration.
我将它与我的 Chef 编排一起使用。
cmd.exe
and call where git-credential-manager.exe
cmd.exe
并调用where git-credential-manager.exe
cmd.exe
call where git.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
again to get the path.where
获取路径。 We need to:我们需要:
C:\\
with /mnt/c/
/mnt/c/
替换C:\\
\\
to /
\\
翻转到/
\\\\
\\\\
转义空格(和括号,如果有的话) So...所以...
"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-credential-manager.exe"
becomes... "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"
My script above has a function for doing just that我上面的脚本有一个功能可以做到这一点
dos_path_to_linux(){
sed -e 's?\\?/?g' -e' s?[cC]:?/mnt/c?' <<<"$1"
}
But, as @12345ieee has since commented , a wslpath
utility has been added to WSL build 17046 .但是,正如@12345ieee 此后评论的那样,一个
wslpath
实用程序已添加到WSL 版本 17046 中。 It's worth checking out, but I don't have access to Windows at this time to verify.值得一试,但我目前无法访问 Windows 进行验证。 (Note that even though a usage statement is given in the release notes in my link, it seems that the command doesn't currently include a usage statement , -h, etc.)
(请注意,即使在我的链接的发行说明中给出了使用说明,但该命令目前似乎不包含使用说明、-h 等)
bash
call git config --global credential.helper "<converted/path>"
bash
调用git config --global credential.helper "<converted/path>"
Using Windows 10 and "WSL", I created a ~/.gitconfig file, but had mistyped the [credential] section label as [credentials].使用 Windows 10 和“WSL”,我创建了一个 ~/.gitconfig 文件,但将 [credential] 部分标签错误地输入为 [credentials]。 I tried running git credential fill and then feeding its output to git credential approve, which might have worked, but I suspect not since it said "usage: git credential [fill|approve|reject]".
我尝试运行 git credential fill 然后将其输出提供给 git credential批准,这可能有效,但我怀疑不是因为它说“用法:git credential [fill|approve|reject]”。 Finally, I simply ran:
最后,我只是跑了:
$ git config --global credential.helper cache
and then did a git pull;然后做了一个git pull; when prompted for user and password I typed them as usual.
当提示输入用户名和密码时,我像往常一样输入它们。 After that, it remembered it.
在那之后,它记住了它。 I found it had added the (correctly named) section to my ~/.gitconfig:
我发现它已将(正确命名的)部分添加到我的 ~/.gitconfig 中:
[credential]
helper = cache
I edited that to provide a much longer timeout:我编辑了它以提供更长的超时时间:
[credential]
helper = cache --timeout=144000
And it all seems to be working nicely now.现在这一切似乎都运行良好。
alias git=git.exe
将简单地使用 windows 中的 git.exe 及其配置
All the answers are overly complicated to this point.到目前为止,所有答案都过于复杂。 And the git documentation does not really help, they like to reference material a lot so you need to follow 2-3 links to get the info you need!
而且 git 文档并没有真正的帮助,他们喜欢参考资料很多,所以你需要按照 2-3 个链接来获取你需要的信息!
git.exe
with WSL!git.exe
与 WSL 一起使用! Use linux git sudo apt install git-all
(I think it comes pre-installed with Ubuntu).sudo apt install git-all
(我认为它预装了 Ubuntu)。git supports 2 methods by default. git 默认支持 2 种方法。 To see what methods you have installed, execute this command:
要查看您安装了哪些方法,请执行以下命令:
git help -a | grep credential
my result was:我的结果是:
credential Retrieve and store user credentials
credential-cache Helper to temporarily store passwords in memory
credential-store Helper to store credentials on disk
@selkieTG covers this in their answer, including for completeness... @selkieTG 在他们的回答中涵盖了这一点,包括完整性......
git config --global credential.helper "cache --timeout 30000"
will cache your password/token for 30,000 seconds (8 hrs 20min)将您的密码/令牌缓存 30,000 秒(8 小时 20 分钟)
git config --global credential.helper "store"
will store plain text password/token in ~/.git-credentials
.将纯文本密码/令牌存储在
~/.git-credentials
。
Plain Text?!!纯文本?! For WSL, I am absolutely OK with plain text here.
对于 WSL,我完全可以在这里使用纯文本。 I enter credentials to run my Windows machine and I enter credentials to sign into WSL2.
我输入凭据以运行我的 Windows 计算机,然后输入凭据以登录 WSL2。 Do I need to hide these?
我需要隐藏这些吗? Not really, it is more of a convenience on my dev box.
不是真的,它在我的开发箱上更方便。
If you really want to use manager-core
you can install it in your Ubuntu version .如果你真的想使用
manager-core
你可以在你的Ubuntu 版本中安装它。 And then use it.然后使用它。
I have just recently updated to WSL2 and in my case the following wasn't working:我最近刚刚更新到 WSL2,在我的情况下,以下内容不起作用:
"/mnt/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
What worked was the following: git config --global credential.helper "/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"
Until I've removed /mnt/
from the path I was getting a "not found" error.在我从路径中删除
/mnt/
,我收到了“未找到”错误。
From what I've investigated there's an issue with mounting windows drives in WSL2 after a clean Windows startup, more details here: https://github.com/microsoft/WSL/issues/4122
And that was the most probable cause in my case.根据我的调查,在干净的 Windows 启动后,在 WSL2 中安装 Windows 驱动器存在问题,更多详细信息请点击此处:
https://github.com/microsoft/WSL/issues/4122
: https://github.com/microsoft/WSL/issues/4122
在我的情况下,这是最可能的原因.
Another reason for this can be a misconfiguration of root directory in /etc/wsl.conf
另一个原因可能是
/etc/wsl.conf
中根目录的错误配置
Couldn't get this working with git-credential-manager.exe
on WSL2 with Debian.无法在 WSL2 和 Debian 上使用
git-credential-manager.exe
进行此操作。 I'd always get remote: Repository not found.
我总是得到
remote: Repository not found.
with no further error.没有进一步的错误。
Instead I did the same with git-credential-manager-core.exe
so my config is now credential.helper=/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe
.相反,我对
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
。 This worked right away, with GitHub 2FA/PAT set up on Windows before hand.这立即奏效,事先在 Windows 上设置了 GitHub 2FA/PAT。
I have the following git versions:我有以下 git 版本:
download: (gcmcore-linux_amd64.2.0.567.18224.deb) https://github.com/GitCredentialManager/git-credential-manager/releases/tag/v2.0.567下载:(gcmcore-linux_amd64.2.0.567.18224.deb) https://github.com/GitCredentialManager/git-credential-manager/releases/tag/v2.0.567
install:安装:
sudo apt install gcmcore -y or sudo apt install gcmcore -y 或
sudo dpkg -i <path-to-package.deb> (gcmcore-linux_amd64.2.0.567.18224.deb)须藤 dpkg -i <path-to-package.deb> (gcmcore-linux_amd64.2.0.567.18224.deb)
configure:配置:
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1导出 DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
git-credential-manager-core configure git-credential-manager-core 配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.