I have a GitHub account, it is oanhnn, but at office, I couldn't use my personal GitHub account. I have to use an other GitHub account, eg supermen. I want use both two accounts on same computer (use without typing password each times, when git push or pull).
Using ssh keys and ssh configure file to alias host and using multiple GitHub accounts
-
Make key pair for each accounts and add it to GitHub accounts.
-
Make ssh configure file (
~/.ssh/config) like:# Default github account: oanhnn Host github.com HostName github.com IdentityFile ~/.ssh/oanhnn_private_key # Other github account: supermen Host github-supermen HostName github.com IdentityFile ~/.ssh/supermen_private_key -
Added ssh key to your agent by command:
$ ssh-add ~/.ssh/oanhnn_private_key $ ssh-add ~/.ssh/supermen_private_key -
Check that repo recognizes keys.
$ ssh -T [email protected] $ ssh -T git@github-supermen -
Clone projects
$ git clone git@github-supermen:org2/project2.git /path/to/project2 $ cd /path/to/project2 $ git config user.email "[email protected]" $ git config user.name "Supper Men"
Done! Have goodluck!