drcabana.org
Computational divertissements


ssh with multiple github accounts

Posted on

Suppose you maintain several github accounts (say personal and work accounts) and have separate ssh keys for the accounts. You can use host aliases in your ssh config file to simplify your ssh/github interactions. Include entries in along these lines in ~/.ssh/config:

# Personal account
Host personal.github.com
  User git
  IdentityFile ~/.ssh/personal_key
  HostName github.com

# Work account
Host work.github.com
  User git
  IdentityFile ~/.ssh/work_key
  HostName github.com

A work project using the above might have something like this in its .git/config file.

url = ssh://work.github.com/user_name/work_project.git

A personal project would instead use something like

url = ssh://personal.github.com/user_name/personal_project.git

The host alias in the url implicitly selects the the appropriate ssh key to use.