Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission failure cloning in Git in Windows

Tags:

git

When I clone from GitHub using CMD or PowerShell with ssh-agent on Windows 10 v.1909, the following shows:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

However, I ran ssh -vT [email protected] and the key does work

debug1: Offering public key: {My key}

And

Hi {My username}! You've successfully authenticated, but GitHub does not provide shell access.

But with Git bash I can clone just fine.

This also happen with GitLab.

I tried

Host *
 ForwardAgent yes

in .ssh/config and it doesn't work.

I also tried every solution from GitHub Support Page and GitHub Community Forum and still doesn't work.

PS. I prefer Windows cmd.

like image 866
buratud Avatar asked Apr 30 '20 14:04

buratud


People also ask

How do I fix Permission denied in git?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

Can clone git repository permission denied?

If your attempt to clone a GitHub repository over SSH is foiled by GitHub's Permission denied (publickey) SSH error, there's usually a quick fix. GitHub's Permission denied (publickey) error is usually caused by one of the following three issues: You have used an incorrect email address in the GitHub SSH URL.


2 Answers

In your Powershell session, try:

$env:GIT_SSH_COMMAND='ssh -Tv'; git clone [email protected]:myuser/myrepo.git

And see where SSH is looking for your default id_rsa/id_rsa.pub key pair.

Make sure, if the private key is passphrase-protected, to launch ssh-agent first.

The OP mentions:

Apparently, Git doesn't use native 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"

Hence the workaround:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

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

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=

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%

That way, I am sure I will use Git tools first (incuding an OpenSSH one) before anything else.

like image 131
VonC Avatar answered Nov 14 '22 22:11

VonC


It turns out that git doesn't use native OpenSSH. Here what's I did

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

Reference here

like image 21
buratud Avatar answered Nov 14 '22 23:11

buratud