3

I have multiple SSH keys on a single device.

// example
id_rsa_github_office.pub , id_rsa_github_personal.pub

How can I manage multiple SSH keys without conflict on a single device?

Krunal Rajkotiya
  • 1,070
  • 9
  • 14
  • 1
    Please be more specific about what you want. If you just want to "use both keys in one pc", why don't you just copy over the two `id_rsa*` files and store them under different names? The name is arbitrary. On the ssh command line you can specify an `-i identity_file` option to select between the two keys. Also in the `~/.ssh/config` you can configure to use one key for one ssh connection and the other for a second (or all other) ssh connection(s). If you search for these keywords, there's ample documentation on this on the net. – cfi Jan 06 '16 at 13:37

2 Answers2

4

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 bitbucket.org 
  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 bitbucket.org
IdentityFile ~/.ssh/workid

Host personalid
HostName bitbucket.org
IdentityFile ~/.ssh/personalid

PS

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

How to add ssh key to github account?

  • Login to github account
  • Click on the rancher on the top right (Settings)
    github account settigns
  • Click on the SSH keys
    ssh key section
  • Click on the Add ssh key
    Add ssh key
  • Paste your key and save

And you all set to go :-)

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
-1

Create config file inside the .ssh directory with name config.

Then inside the config file write down these configurations. Change the your-file-name to your SSH key file-name and change the your-host-name to your preferred host-name

Host <your-host-name>
 HostName github.com
 User git
 IdentityFile ~/.ssh/<your-file-name>

The config file should be looking something like this after the edit.

enter image description here

Then we will clone the same old way using a modified URL

$ git clone git@github-personal:GhostWolfRider/Angular-Admin-Dashboard.git

Check out this medium article to know more >>

Generate & Manage Multiple SSH Keys on a Single Device

Let me know if you still have any questions.

Krunal Rajkotiya
  • 1,070
  • 9
  • 14