From https://gist.github.com/oanhnn/80a89405ab9023894df7
I have two Github accounts: defaul for work and personal. I want to use both accounts on same computer via git ssh (without typing password everytime, when doing git push or pull).
Use ssh keys and define host aliases in ssh config file (an alias per account).
-
Generate ssh key pairs for accounts and add them to GitHub accounts.
-
Edit/Create ssh config file (
~/.ssh/config
):# Default github account Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes # Other github account: superman Host github-personal HostName github.com IdentityFile ~/.ssh/personal_id_rsa IdentitiesOnly yes
-
Add ssh private keys to your agent:
$ ssh-add ~/.ssh/oanhnn_private_key $ ssh-add ~/.ssh/superman_private_key
-
Test your connection
$ ssh -T git@github.com $ ssh -T git@github-personal
-
Now all are set, just clone your repositories using github alias
github-personal
$ git clone git@github-personal:pavelfomin/spring-boot-rest-example.git