0

This one is rather complicated to describe. I have two github accounts, I will refer to them as github A and B.

I had created a local repo X and tried to connect it to a new remote repo I created on github account A. However, my default github login credetials were set for my github account B. I went through this tutorial and was able to add a second key created in my .ssh to allow me access to acct. A at will. This method worked and allowed me to add the new remote repo on github account A to my local repo X. I could then push origin to master just fine.

I then made a clone of the same repo X on github account A and placed it in a new local location (same drive, different folder) which I will refer to as local repo Y. I then tried to push changes to the same remote repo on github A and it denies me saying I'm trying to access using my username for my remote github B account.

I tried re-adding the remote url via the same special .ssh key previously created for repo X and use it for the local repo Y but it says it already exists.

I'm looking for a simple solution here, hopefully one exists. I would appreciate your help on this.

Derek Brown
  • 4,232
  • 4
  • 27
  • 44
teaman
  • 469
  • 7
  • 18
  • 1
    It's not clear why Derek changed my title. New title doesn't state what I did. I'm not pushing a single repo to multiple accounts but to the same account. The problem is that the default .ssh key was for the other github account so I had to take steps to add a second .ssh key and use it for remote access. – teaman Nov 06 '17 at 04:38

3 Answers3

1

You can test what actual key is used with:

ssh -Tv <yourSSHConfigEntry>

Make sure to use an ssh URL like yourSSHConfigEntry:/ (no need to prefix it with git@: the User should be in your ~/.ssh/config file)
The idea is: your SSH config file should use the right private key, whose public key has been registered to the right GitHub account.

Check the remote URL: git remote -v. If it starts with git@github.com, it won't use the ssh config entry.

Type:

git remote set-url origin <my-github-acct-A>:<user>/<repo>

That will use the SSH config entry, and make sure the User in it is "git".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • When I view my ~/.ssh/config file it has: Host * as the first entry. There are two more Host entries, one for my bitbucket account and the 3rd for my github account A that I referred to above. Running the SSHConfigEntry string as you suggested with the ssh command and the -Tv options, it says the host for my 3rd entry it says it is applying options for *. – teaman Nov 06 '17 at 06:39
  • I also looked in my Keychain Access (I'm on a Mac) app and searched for github and got about 11 records. It seems I may have some extra un-needed entries but not sure. – teaman Nov 06 '17 at 06:47
  • @teaman keychain access is for https credentials caching, so no relation. Is your URL using your third entry in your config file? And is that private key referenced by the third entry the right one (ie matching the public key registered to your GitHub account)? – VonC Nov 06 '17 at 06:56
  • It is not using the third entry. It ends the ssh -Tv by saying ssh: Cound not resolve hostname ://: nodename nor servname provided, or not known. Those <> values are placeholders. Yes the third key is the right one that I created and used for the original local repo location. – teaman Nov 06 '17 at 07:00
  • 1
    @teaman Exactly: your URL *must* :/. See as an example: https://stackoverflow.com/a/45578300/6309 or https://stackoverflow.com/a/45228981/6309 – VonC Nov 06 '17 at 07:16
  • Unfortunately, adding on the repo path doesn't change the output error. debug1: Reading configuration data /Users//.ssh/config debug1: /Users//.ssh/config line 1: Applying options for * debug1: Reading configuration data /etc/ssh/ssh_config ssh: Could not resolve hostname ://: nodename nor servname provided, or not known – teaman Nov 06 '17 at 07:27
  • 1
    @teaman is your ssh config file really like https://stackoverflow.com/a/45578300/6309 or https://stackoverflow.com/a/45228981/6309? – VonC Nov 06 '17 at 07:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158292/discussion-between-teaman-and-vonc). – teaman Nov 06 '17 at 07:35
0

I'm pretty sure the issues you're running into are a result of managing multiple accounts on the same computer, regardless of the repos being duplicates. If you haven't already, I'd suggest you take a look at the very detailed answers provided here.

tterb
  • 151
  • 2
  • 8
0

I have been through this trouble many times and have resolved it by setting the ssh config rules or by enforcing the ssh-agent to have the correct ssh key alone.

I have documented the entire process and Freecodecamp published the article. Here's the link! Hope this will help whenever you come across this use case. :)

Bivil M Jacob
  • 471
  • 4
  • 9