Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save erranddev/ea364722225dcc6ab9c59b571f63eb1f to your computer and use it in GitHub Desktop.

Select an option

Save erranddev/ea364722225dcc6ab9c59b571f63eb1f to your computer and use it in GitHub Desktop.
Using multiple github accounts with ssh keys

Problem

I have a github account, it is oanhnn, but when i join a private project in company, i have to use an other github account, eg suppermen. I want using two accounts without typing password each times, when git push or pull.

Solution

Using ssh keys and ssh configure file to alias host and using multiple github accounts

How to?

  1. Make key pair for each accounts and add it to github accounts.
  2. Make ssh configure file (~/.ssh/config) like:
    # Default github account: oanhnn
    Host github.com
       HostName github.com
       IdentityFile ~/.ssh/oanhnn_key
       
    # Other github account: suppermen
    Host github-suppermen
       HostName github.com
       IdentityFile ~/.ssh/suppermen_key
    
  3. Added ssh key to your agent by command:
    $ ssh-add ~/.ssh/oanhnn_key
    $ ssh-add ~/.ssh/suppermen_key
    
  4. Check that repo recognizes keys.
    $ ssh -T git@github.com
    $ ssh -T git@github-suppermen
    
  5. Clone projects
    $ git clone git@github-suppermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "suppermen@org2.com"
    $ git config user.name  "Supper Men"
    

Done! Have goodluck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment