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?

Community
  • 1
  • 1
Fantikz
  • 55
  • 5
  • One Question: _Why_ do you need two different keys? – tkausl Jun 23 '16 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. – Fantikz Jun 23 '16 at 17:13

1 Answers1

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.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    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. – Fantikz Jun 23 '16 at 17:17
  • You have to rename the keys accordingly and place each one under its account – CodeWizard Jun 23 '16 at 17:20
  • 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. – CodeWizard Jun 23 '16 at 17:21
  • So I need to rename the private and public key, then re upload the public key (with the new name) to the git servers? – Fantikz Jun 23 '16 at 17:23
  • after you rename the files execute this in the terminal/bash: `eval $(ssh-agent)` and now try to `pull/fetch` – CodeWizard Jun 23 '16 at 17:31