3

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 e.g. 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.

mdx
  • 534
  • 3
  • 16
  • Hi, and welcome to Stack Overflow. It seems you've done all the normal ssh/git debugging steps. If you can `ssh git@github.com` you should be good. However, it's possible your `git` is not using the same ssh configuration as your `ssh` commands. How did you install Git and how did you install ssh? It's possible it's not communicating with your ssh-agent. Try running the `git` commands in the same shell where `ssh` works. – Schwern May 27 '18 at 22:16
  • 1
    There should not be a space in the middle of `git@github.com: username/github-remote.git` – Dietrich Epp May 27 '18 at 22:24
  • @Schwern As for git, I downloaded the .exe from https://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, so I guess that's good. Feel free to go into more detail if I misunderstood what you meant, I'd really appreciate it. – mdx May 27 '18 at 22:48
  • @DietrichEpp Thanks for pointing that out, although I added the space accidentally while posting. It's not in the actual address. – mdx May 27 '18 at 22:50

1 Answers1

2

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.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Turns out that was it. Installing git via Cygwin did the trick! Thanks a lot :) – mdx May 28 '18 at 08:33