Sunday, 11 May 2025

Access two github accounts in one linux machine

Assume you already can access your person github repositories using public key id_rsa.pub

  1. Create another ssh private / public key pair
    # file name: ~/.ssh/id_rsa2
     ssh-keygen
  2. upload public key to your company's github
  3. create a ssh config at .ssh/config
    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
      AddKeysToAgent yes
      ServerAliveInterval 60
      ServerAliveCountMax 30
    
    # Work GitHub account
    Host github-work
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa2
      AddKeysToAgent yes
      ServerAliveInterval 60
      ServerAliveCountMax 30
  4. clone work repository
    git clone git@github-work:mycompany/jackt.git
  5. clone your person repository as normal because it will use the default ssh config

No comments:

Post a Comment