'Managing two ssh keys

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?



Solution 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 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 :-)

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2