Windows中Git中的权限失败克隆 [英] Permission failure cloning in Git in Windows
问题描述
当我在Windows 10 v.1909上使用ssh-agent使用 CMD 和 PowerShell 从GitHub克隆时,显示如下:
When I clone from GitHub using CMD and PowerShell with ssh-agent on Windows 10 v.1909, the following shows:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
但是,我运行了ssh -vT git@github.com
并且密钥确实起作用
However, I ran ssh -vT git@github.com
and the key does work
debug1: Offering public key: {My key}
还有
Hi {My username}! You've successfully authenticated, but GitHub does not provide shell access.
但是使用Git bash可以很好地进行克隆.
But with Git bash I can clone just fine.
GitLab也会发生这种情况.
This also happen with GitLab.
我尝试过
Host *
ForwardAgent yes
在.ssh/config
中,它不起作用.
我还尝试了 GitHub上的所有解决方案支持页面和
I also tried every solution from GitHub Support Page and GitHub Community Forum and still doesn't work.
PS.我更喜欢Windows cmd.
PS. I prefer Windows cmd.
推荐答案
在Powershell会话中,尝试:
In your Powershell session, try:
$env:GIT_SSH_COMMAND='ssh -Tv' git clone git@gitlab.com:myuser/myrepo.git
然后查看SSH在哪里寻找默认的id_rsa/id_rsa.pub密钥对.
And see where SSH is looking for your default id_rsa/id_rsa.pub key pair.
如果私钥受密码保护,请确保首先启动ssh-agent .
Make sure, if the private key is passphrase-protected, to launch ssh-agent first.
OP提到:
显然,Git不使用本机OpenSSH.
Apparently, Git doesn't use native OpenSSH.
那是错误的.可能 GitHub桌面不使用OpenSSH,如
That is false. Maybe GitHub Desktop does not use OpenSSH, as seen in desktop/desktop issue 5641: "Desktop does not use OpenSSH on Windows if running, favours embedded SSH"
解决方法:
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
但是Git本身会这么做:
But Git itself does:
D:\prgs\gits\current\bin>where ssh
D:\prgs\gits\current\usr\bin\ssh.exe
D:\prgs\gits\current\bin>ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020
这比Windows版本更新:
This is more recent than the Windows one:
C:\WINDOWS\System32\OpenSSH\ssh.exe -V
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
(Winver:1909,build 18363.836 =
(Winver: 1909, build 18363.836=
这就是为什么我总是使用自己的自己的路径启动工具的原因
That is why I always launch tools with my own PATH
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
这样,我确定我将首先使用Git工具(包括OpenSSH).
That way, I am sure I will use Git tools first (incuding an OpenSSH one) before anything else.
这篇关于Windows中Git中的权限失败克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!