coffeequant coffeequant - 1 year ago 120
Git Question

How to use multiple ssh keys in github?

The ssh configuration in github seems to be a nightmare. I have multiple github accounts, but for which I can have multiple ssh keys. In the github ssh configuration section they mention this...
ssh-keygen -t rsa -C ""
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.

We strongly suggest keeping the default settings as they are, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.

# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Why should I always use id_rsa file, it will overwrite my existing keys. Anyway I give a new name here and generate the key. I do all the other steps of adding it to agent, updating in github ssh keys section.

After completing all those steps I come to the final step which is....

ssh -vT
Hi animesh11! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3128, received 1976 bytes, in 0.5 seconds
Bytes per second: sent 6077.0, received 3838.9
debug1: Exit status 1

Everything hunky dory but somehow git clone still complains...

MacBook-Pro:Documents animeshsaxena$ git clone
Cloning into 'devbox'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

I am up to my wits end why the ssh -vT works and simple cloning doesn't. It doesn't seem logical, why would github put this step in the manual if they know it's freaking useless.

Any ideas??

Answer Source

I'd use .ssh config to set up different configurations for each particular user.

For example, edit (or create) the config file in the .ssh folder under your users root, and add something similar to this:

Host user1-github
    User git
    IdentityFile ~/.ssh/user1_rsa
Host user2-github
    User git
    IdentityFile ~/.ssh/user2_rsa

Where user1_rsa and user2_rsa are the outputs of ssh-keygen -t rsa -C "" and ssh-keygen -t rsa -C ""

Then, when testing simply use ssh -vT user1-github and ssh -vT user2-github.

Also, when cloning repos use git clone user1-github:username1/project.git or git clone user2-github:username2/project.git.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download