简体   繁体   中英

Github SSH access: Permission denied (publickey)

I've recently set up a git repository on Win10 via Cygwin and now I'm trying to make it track a remote repo on github.

The problem is, that after adding a remote like this:

 git remote add github-remote git@github.com:username/github-remote.git

I cannot access it in any possible way (pushing, fetching, displaying additinal info by 'show'). All I get is this:

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

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

Although I know this topic's been discussed a lot, none of the solutions I found actually helped. That's why I decided to post yet another question.

Here's what I did, step-by-step:

1) Generated the pub-priv keypair:

ssh-keygen -t rsa -b 4096 -C "mymail@ex.com"

Tried with both - a default and a custom directory for the id_rsa files. Same results.

2) Ran the ssh agent (or checked for it running, to be precise):

eval $(ssh-agent -s)

3) Added the key to the agent

ssh-add ~/.ssh/id_rsa

4) Copied the id_rsa.pub to github

5) Checked if the connection's set properly

ssh -T git@github.com

... with a promising result of

You've successfully authenticated, but GitHub does not provide shell access.

From what I learned this error may be due to git's address not being included in the /.ssh/known_hosts file. The thing is (as far as I know) that it is being inserted automatically eg with 'ssh -T' so I doubt it's the case, either. Although tried that as well:

ssh-keyscan -t rsa github.com | ssh-keygen -lf -

Another possible problem could be my private key's access being available too widely for the users, but I checked that, too.

With all that said I have no further idea how to fix this one, so I'd appreciate any help. Thank you in advance.

As for git, I downloaded the .exe from git-scm.com/download/win. SSH on the other hand I had to install as a Cygwin's package, and it's Cygwin's mintty in which I run all of the commands...

Mixing Cygwin and Git For Windows is likely the problem. While I'm sure there's a way to make them work, it's simplest to stick to one or the other.

Git For Windows comes with its own "Git Bash" shell and, I believe, ssh. Use that.

Or, if you want to stick with Cygwin, get Git from from Cygwin and use that.

Running Git through Cygwin from Windows might also be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM