Adding Multiple GitHub Accounts for SSH Communication

You may have multiple github accounts. In this post, we cover setting up ssh authentication for multiple github accounts from one computer, so pushing code to and from different github accounts is an easy process

Step 1. Generate the extra key in .ssh directory and copy it into clipboard

ssh-keygen -t rsa -C ""
pbcopy < ~/.ssh/

In the line 1, it generates new ssh key into file(for example, in ‘’) and in line 2, it copies the new key into clipboard

Step 2. Paste new key into the GitHub account
In your account on the, go to the ‘Account Settings’-> ‘SSH Keys’ and past the new key

Step 3. Update ssh config (~/.ssh/config)
On you computer, in the ~/.ssh directory add the entry

	User git
	IdentityFile ~/.ssh/id_rsa_new_key
	User git
	IdentityFile ~/.ssh/id_rsa_new_key2

Here the ‘’ is part of the git remote repo url(i.e. The ‘IdentityFile’ is file created in Step 1. When you are going to push the content, ssh looks up the url of remote repo and compares it to the Host ‘’ in .ssh/config file to find the action HostName(i.e. along the ssh key to use for authentication

Step-4. Add the key to ssh cache

ssh-add ~/.ssh/id_rsa_new_key

Step-5. Update the git remote repo accordingly in the git directory

git remote add origin

Here the ‘’ part is the same specified in the ~.ssh/config file. You can also manually edit it in the repository .git/config file


1. ERROR: Permission to gitHub-account/remoteRepo.git denied to gitHub-account.
fatal: Could not read from remote repository.
The step 3 was missed or it was needed to be do again:

ssh-add ~/.ssh/id_rsa_new_key

This solved the problem. Important to note that this keep happening often time on Mac Lion where i have to re-add the key to the ssh-key cache often time

2. ssh: Could not resolve hostname nodename nor servname provided, or not known
I am not sure the cause, but after authenticating directly with github as following, the error went away:

ssh -T

Useful links: