GitHub and multiple accounts


#1

Hi there!

I have followed this post and having a trouble with my default account getting the following error message. Also, I have checked my both accounts SSH keys were added and named correctly as mentioned in the post. But still getting it.

Thoughts? what I’m doing wrong? Any help would be greatly appreciated.

Thanks in advance. :slight_smile:


#2

The user you’re pushing from is abdurrehman-net but you’re pushing to a repo owned by Abd-Ur-Rehman.
Is that what you’re trying to do? You’ll need to add the former to the repository as a collaborator through GitHub.


#3

I’m trying to push it to user Abd-Ur-Rehman as the user the same user as owner Abd-Ur-Rehman My other user abdurrehman-net works. fine.


#4

You must’ve cloned the repo using the wrong account then. In the future, when cloning a repo, you can specify the user like below, otherwise it uses the global default user.

git clone user@github.com:username/repository.git

For now, you can remove the remote origin and replace it with the correct one, for instance:

git remote set-url origin Abd-Ur-Rehman@github.com:Abd-Ur-Rehman/travel-site.git

You can also check the current remotes using the following command to verify that it worked.

git remote -v

#5

I have added that correctly, I’m trying to push it here and here’s the remote path.

image

I have two accounts so for other GitHub account which is git@github-abdurrehman-net all is working fine with the SSH key, when I push to my 2nd account git@github-abdurrehman-net everything works fine as it should. But when I push to Abd-Ur-Rehman I get that error. Here’s the config file that I have in my ~/.ssh folder.

#Default GitHub
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-abdurrehman-net
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_abdurrehman_net

BTW, on my account abdurrehman-net I’m able to push changes as Abd-Ur-Rehman but I can’t do it for this account it self and when adding the remote origin path it works with both URLs for the abdurrehman-net account.

For example when I add the URL as:

git@github-abdurrehman-net:abdurrehman-net/repo.git
git @github.com:abdurrehman-net/repo.git.

Not sure what I’m doing wrong. :confused:


#6

Sounds to me like both git@github.com and git@github-abdurrehman-net are pointing to the same “abdurrehman” user. You need one of them to be pointing to “Abd-Ur-Rehman” in order to push changes to their repositories if you don’t want to use collaborator privileges.

You can generate a new key and add it to the Abd-Ur-Rehman account, and set it in the ~/.ssh/id_rsa file (always safe to make a copy of the existing file first).


#7

GitHub provides a test facility for ssh-based connections:

$ ssh -Tv git@github-abdurrehman-net
...
Hi $USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
...

I setup a single user with the config you’ve described above and was able to test the ssh config, clone, and push.


#8

I have done this and still getting that same error even though in both accounts separate key is added. I’m stuck with this trying to figured out since Friday and got no luck. :disappointed:


#9

I see now both are appoint to the same user.

How can I make the git@github.com for the user Abd-Ur-Rehman?


#11

Anybody here?


#12

Hey,

GitHub uses SSH keys to authenticate you, so you can create a new SSH key and attach it to your “Abd-Ur-Rehman” account on GitHub, save the key in one of your identity files, and update the SSH configuration so that one of your hosts uses that key.

The original tutorial you were following has all the instructions:

  • Create a new SSH key
  • Attach the key to your GitHub account (Abd-Ur-Rehman)
  • Save the key to a new identity file (using ssh-add)
  • Open the ~/.ssh/config file in your editor
  • Edit the "git@github.com" host and set the correct identity file from step #2

#13

I have followed this and did start over agian but the key I add 1st into SSH agent only works for me the 2nd one doesn’t work. Is there anyway I can mae these working at the same time? When I test the connection see below:


#14

You’re absolutely certain that the git@github.com host is using the SSH key for the Abd-Ur-Rehman account?

  • Did you overwrite ~/.ssh/id_rsa, or did you add the key to a different file (step 3 above)?
  • Did you make sure that the IdentityFile for git@github.com is pointing to the correct key file?
  • Can you copy and paste your current ~/.ssh/config file?

#15

Thank you so much for your time and reply.

Yeah, I do. I’ve added them separately. I have figured one thing, instead of having each account as a separate host in the config Now my settings are as below:

Host github
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_rsa_abdurrehman-net
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

Now the issue is, the key I add 1st into ssh-agent that only works 2nd one doesn’t.

The key I have above only worked, the 2nd one gives that error. You can see only one work which is above in the following screenshot.


Not sure how to make these work at the same time. :frowning:

Thoughts?

Many thanks.


#16

No problem! :smiley:

Okay, so they merged somehow. It’s fine, we can fix this easily!

I’m going to assume that:

  • ~/.ssh/id_rsa is the private key attached to Abd-Ur-Rehman
  • ~/.ssh/id_rsa_abdurrehman-net is the private key attached to abdurrehman-net

If that’s true, then this configuration should work:

# ~/.ssh/config

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

Host github-abdurrehman-net
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_abdurrehman-net
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

And after you save that, with those two identity files pointing to the different accounts, you should be able to see the different usernames showing up:

ssh -Tv git@github.com
# Hi Abd-Ur-Rehman!

ssh -Tv git@github-abdurrehman-net
# Hi abdurrehman-net!

#17

Yes, that’s true. I just changed the config file with the text you’ve added above.

I do get the success message see here https://gist.github.com/b8f8292f7c05b9e4f995e7e1ad9bab7f

After that, I tried to push I got the same error then. As per this video https://youtu.be/fnSRBRiQIU8?t=253 from the post I change the origin path with the hostname as git@abdurrehman-net:abdurrehman-net/travel-site.git it says that couldn’t resolve after that I revert back to the same github.com host then it give same error. See below:


#18

That’s great! Now we’re making progress. :smiley:

With regards to your command:

git@abdurrehman-net:abdurrehman-net/travel-site.git

I believe that it should be github-abdurrehman-net correct? You missed the “github-” portion. Can you give that a try?

git@github-abdurrehman-net:abdurrehman-net/travel-site.git

#19

OMG! I can’t believe this how did I miss that. It worked! :tada:

Thanks a lot for your time.


#20

No worries mate, glad we could get it working! Don’t hesitate to post on the forums again if you need help with any other tutorials, we’re all here to help. :slight_smile:

Cheers!


#21

Thank you! :+1:

P.S. From now I’ll never ever forget this. :laughing: