0%

Multiple SSH keys Management

Goal

Use different ssh keys for different hosts in git.

Steps

  1. Generate the keys.

    1
    ssh-keygen -t rsa -C "your_email@youremail.com"

    Specify the new id_rsa path.

    1
    Enter file in which to save the key (/Users/user/.ssh/id_rsa): /Users/user/.ssh/id_rsa_company
  2. Evict the oudated Identity cache.

    1
    ssh-add -D
  3. Add ssh key

    1
    2
    ssh-add ~/.ssh/id_rsa
    ssh-add ~/.ssh/id_rsa_company
  4. Create ssh config.

    1
    2
    cd ~/.ssh
    touch config
  5. Modify config.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # Company
    Host Company
    HostName github.company.io
    User yourName
    IdentityFile ~/.ssh/id_rsa_company

    # Myself
    Host Myself
    HostName github.com
    User opsmilesum
    IdentityFile ~/.ssh/id_rsa