2

I'm unable to clone from a work github account repo. I have gone through the steps of generating an ssh key pair and uploading the public key to my work github account. I see with a verbose log clone GIT_SSH_COMMAND="ssh -vvv" git clone git@github.com:<workAccount>/repo.git that the authentication succeeds with the public key. Therefore, I believe this is not an ssh auth problem.

But, when I run ssh -T git@github.com, it reads:

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

Now AlexanderBollbach is the name of my personal github account, not my work github account. So it makes sense that I might get this error 'Could not read from remote repository.' as my personal github account wouldn't have read privileges from my work github account.

My question is therefore, how can I associate this ssh cloning process with the right github account? In the reading I've gone on ssh, I've not understood any concept of how ssh could be associated with one github account versus another. I would greatly appreciate not just a fix but a proper understanding of how succeeding with the private/public key in this case just wasn't sufficient in cloning the repo.

Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80
  • Where did you save the key for your work account? Try using that with `ssh-agent` and `ssh-add`, as in `ssh-agent bash` followed by `ssh-add ~/.ssh/work_ed25519` and the clone. Or just `GIT_SSH_COMMAND="ssh -i $HOME/.ssh/work_ed25519"`. – Ry- Jul 13 '17 at 00:24
  • that didn't do it. I'm still confused about how `ssh -T git@github.com` prints out my personal github user account name. How is ssh associated with one github account vs another. i don't get that. – Alex Bollbach Jul 13 '17 at 00:32
  • It’s all about the private key you use, which will default to `~/.ssh/id_*`. Do you have anything in your `.ssh/config`, or is `ssh` an alias? And are you sure the SSH key you used when trying last time was actually associated with your work GitHub account? – Ry- Jul 13 '17 at 00:41
  • all i did was key-gen a new key pair, submit the public key to github ( the work account) and try to clone. so the fact that ssh is some how associated with my personal account is totally mysterious to me. in the config file i did as you said, and told ssh to use that newly generated key. i don't think ssh is an alias. this is all just way over my head. – Alex Bollbach Jul 13 '17 at 01:01

2 Answers2

2

"I'm still confused about how ssh -T git@github.com prints out my personal github user account name":
Simple: if the default public key ~/.ssh/id_rsa.pub is registered in your public account, that account would be the one displayed in a ssh -Tv git@github.com.

If you want to manage multiple account (especially when it comes to pushing, which requires clear authentication and ownership of the target repo), you need an ~/.ssh/config file, as seen here.

#Personal GitHub
Host persgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_perso

#Personal Work
Host workgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work

Then, to successfully clone your private repo:

git clone workgh:<workAccount>/<workRepo>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Solution from Tombart:

Make sure you have correct url in ~/.git/config:

url = git@github.com:<workAccount>/repo.git

If it's your first push, you'll need to set up correct upstream

$ git push -u origin master

You can check which key is used by:

$ ssh -vvv git@github.com

This should work.

Helpful resources

Suriyaa
  • 2,222
  • 2
  • 25
  • 44