6

I'm using two-factor auth and that's why HTTPS isn't convenient way to work with GitHub repos and gists.

I have correct config and github_pr_key files in my ~/.ssh directory.

I'm able to clone all my personal and public repos.

But I can't clone via SSH any of my private or public gists, I have this error:

~/Desktop >> git clone git@gist.github.com:d1b8041051e62aa34f337b3dabc77d9a.git                                                                                                                                
Cloning into 'd1b8041051e62aa34f337b3dabc77d9a'...
The authenticity of host 'gist.github.com (192.30.253.118)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl22E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gist.github.com,192.30.253.118' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How it can be fixed?

Jakuje
  • 24,773
  • 12
  • 69
  • 75
kagarlickij
  • 7,327
  • 10
  • 36
  • 71

1 Answers1

8

Check first the reasons mentioned in "Error: Permission denied (publickey)".
Double-check the output of ssh -Tv git@github.com, to confirm your public key is registered on your GitHub account.

But don't forget that you can still use https with 2FA.
Create a PAT (Personnal Access Token), and use it as password.
That should be enough to allow you to clone anything, including your private Gists.

Finally, try to clone through ssh with git@github.com, not git@gist.github.com (as seen in 2013, even though git@gist.github.com should work):

git clone git@github.com:d1b8041051e62aa34f337b3dabc77d9a.git <=== does work 
NOT
git clone git@gist.github.com:d1b8041051e62aa34f337b3dabc77d9a.git  

Just for testing, try also:

git clone ssh://git@gist.github.com/d1b8041051e62aa34f337b3dabc77d9a.git  

(this time with git@gist.github.com)


As noted by Jacktose in the comments:

If ssh -Tv git@github.com works, try ssh -Tv git@gist.github.com and compare.

In my case, the latter was using the wrong public key because .ssh/config specified IdentityFile under Host github.com.
I changed that to Host github.com *.github.com and problems solved.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've executed ssh -Tv git@github.com and it seems to be fine: http://prntscr.com/fez2gn – kagarlickij Jun 02 '17 at 08:10
  • @КагарлицкийДмитрий It does indeed... Can you clone one your your private repo (repo, not gist) with ssh? Regarding gist, would at least an https clone work (with a token as password)? – VonC Jun 02 '17 at 08:46
  • I can clone private repos via SSH and HTTPS;and I can clone Gists via HTTPS, but not via SSH – kagarlickij Jun 11 '17 at 09:17
  • thanks, the correct one is git clone git@github.com:d1b8041051e62aa34f337b3dabc77d9a.git – kagarlickij Jun 12 '17 at 11:13
  • If `ssh -Tv git@github.com` works, try `ssh -Tv git@gist.github.com` and compare. In my case, the latter was using the wrong public key because .ssh/config specified `IdentityFile` under `Host github.com`. I changed that to `Host github.com *.github.com` and problems solved. – Jacktose Nov 08 '22 at 23:15
  • 1
    @Jacktose Thank you for the feedback. Good point. I have included your comment in the answer for more visibility. – VonC Nov 08 '22 at 23:35