GitHub Users,
I am newbie on github and have some issue with git setup.
I have 2 account with different users on github and i have setup git on my system 2 times
First /.ssh folder (as usual) (contain id_rsa which copied in first
account)
Second /.ssh/new folder (contain id_rsa which copied in
second account)
now at the time of push how can i switch between ssh key?
Because if i would like to push for second account it will use .ssh key instead of .ssh/new and gives me error.
Please make me correct if i am understood something wrong here.
Thanks.
(I’ve voted to close this as a possible duplicate, but I might as well add a similar answer anyway.)
When using the SSH transport, GitHub identifies you as a user based on the SSH key that you use to authenticate. So, you need to make sure that git is using one SSH key for one repository and another for the other.
I’m going to assume that:
user1, and you’ve added to that account the public key corresponding to your local private key/home/whoever/.ssh/id_rsa. Let’s say that the repository you’re interested in accessing asuser1isuser1/whateveron GitHub.user2and you’ve added to that account the public key corresponding to your local private key/home/whoever/.ssh/new/id_rsa. Let’s say that the repository you’re interested in accessing asuser2isuser2/whateveron GitHub.The simplest way to do deal with this is to create a new “remote” (i.e. a nickname for a remote repository) for each repository, where the hostname is in each remote’s URL is actually an alias that you’ve set up in
~/.ssh/config. (If that config file doesn’t exist, you’ll have to create it.)For example, one entry in the
~/.ssh/configfile might look like:Then you can add a remote called
gh-user1, say, with:… and then if you want to push your
masterbranch to the repositoryuser1/whateveron GitHub using the~/.ssh/id_rsakey, you can just do:In order to push as the other user (
user2) to the second repository, you need to add a second alias to you~/.ssh/configfile. For example:Then to push to that second repository as the different user, you can just do: