3

So I just spent ~ 4 hr trying to get an repo working under an SSH URL on windows, I'm almost there, but I run into this weird issue.

I am able to use

git push origin master
git fetch origin master
ssh git@github. #tells me authentication is successful but shell access is not allowed

and all the local commands. However, when I try to do git pull, I get:

-bash-4.1$ git pull
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
-bash-4.1$

I do have id_rsa and id_rsa.pub under %HOME%/.ssh and the public key is added to my GitHub account. My git URL is also correct.

EDIT

-bash-4.1$ git --version
git version 1.8.5.2.msysgit.0
XrXr
  • 2,027
  • 1
  • 14
  • 20

3 Answers3

2

The problem may be persisting because git and cygwin have different .ssh directories.

When you do ssh git@github it uses the one specified in .ssh folder of cygwin, but when you do a git pull it uses the id_rsa present in git bash's .ssh folder.

See my question => ssh clone not cloning repo in git

Community
  • 1
  • 1
Ashish Gaur
  • 2,030
  • 2
  • 18
  • 32
  • Bingo! git pull was reading from cygwin's /home//.ssh and ssh is reading from %HOME%/.ssh! Weird how fetch and push reads from %HOME% but pull doesn't... – XrXr Feb 04 '14 at 07:01
  • 1
    @XrXrXr I had the same problem but I can do git pull and clone, just not git push. (I am also under cygwin.) Do you know where exactly are the two .ssh folder? For me the private keys is stored in ~/.ssh folder. (`$HOME` **is** `/home/`) In cygwin, `which git` will give `/usr/bin/git` – Weishi Z Sep 15 '14 at 04:31
  • @WeishiZeng This question is so old that I'm hesitant to even reply to this. Here it is: `%HOMEPATH% -> \Users\{username}`, `%HOME` -> `/cygdrive/c/Users/{username}`. The default value of %HOMEPATH% is set by Windows. %HOME% is set by cygwin – XrXr Sep 15 '14 at 04:49
  • Also `%USERPROFILE%` might be useful. Read http://en.wikipedia.org/wiki/Environment_variable – XrXr Sep 15 '14 at 04:55
  • @XrXrXr Thanks for still replying though. I guess I confused you and we might not be in the same problem. I am running git push in Cygwin on windows 7. And I installed git and ssh in Cygwin. (in windows `C:\Users\{username}`, there isn't any .ssh folder.) – Weishi Z Sep 15 '14 at 05:23
2

Here is how I solved my problem:

Create a file named config file under cygwin64/home/<username>/.ssh

Add line IdentityFile <path to your private key> to it

XrXr
  • 2,027
  • 1
  • 14
  • 20
1

Are you perhaps pulling from a different location?

Try:

git pull origin master
Loe
  • 327
  • 2
  • 5