1

I've created two different SSH keys. One for an account on Github, and another for a local git server. They were created at different times, and both had the name id_rsa.

I now need to access both of these accounts under the same username. I've followed this similar problem in an attempt to resolve my problem. It does not seem to work.

The problem seems to be renaming my keys. When I change the name on either key to something other than "id_rsa", the link between me and the Git server breaks. As soon as I change it back, the link will be restored. I tried putting them in their own directories within my .ssh folder so that they can keep their original file names, but both ended up breaking.

Does the filename of my public key on the host servers need to match the file name on my computer?

2
  • One Question: Why do you need two different keys? Commented Jun 23, 2016 at 17:06
  • Having one key for both servers would be a possible solution. I figured since the two git servers are unrelated, it might be best to keep separate keys for each one. Commented Jun 23, 2016 at 17:13

1 Answer 1

1

Create a SSH config file

When you have multiple identity files, create a SSH config file mechanisms to create aliases for your various identities.

You can construct a SSH config file using many parameters and different approaches.

The format for the alias entries use in this example is:

Host alias 
  HostName github.com 
  IdentityFile ~/.ssh/identity

To create a config file for two identities (workid and personalid), you would do the following:

Open a terminal window.
Edit the ~/.ssh/config file. 

If you don't have a config file, create one.
Add an alias for each identity combination for example:

Host workid
HostName github.com 
IdentityFile ~/.ssh/workid

Host personalid
HostName github.com 
IdentityFile ~/.ssh/personalid

PS

Don't forget to load the keys to your github account.

Sign up to request clarification or add additional context in comments.

5 Comments

This is what I did. But in changing the name of the private keys to "workid" and "personalid", it broke the connection. It might be worth noting that anything I specify within the config file doesn't affect the connection. If I keep "Id_rsa" as my actual file name, but then specify a different name within my config file, it will still connect successfully.
You have to rename the keys accordingly and place each one under its account
This is why you use the key file. the default name for the key id id_rsa, the config file lets you map different names.
So I need to rename the private and public key, then re upload the public key (with the new name) to the git servers?
after you rename the files execute this in the terminal/bash: eval $(ssh-agent) and now try to pull/fetch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.