18 мая 2015 г.

Multiple git accounts (ssh keys) on OSX or Linux


If you need to use multiple git accounts different ssh keys, for example during work on multiple projects. Here solution.

1) Create or open file:
OSX and Linux: ~/.ssh/config

$ touch config

2) Now create aliases for hosts:


#GitHub work account
Host wrkgithub
    HostName github.com
    IdentityFile ~/.ssh/path_to_your_work_github_key

#GitHub private account

Host prvtgithub
    HostName github.com
    IdentityFile ~/.ssh/path_to_your_private_github_key

#Assembla work account

Host wrkassembla
    HostName git.assembla.com
    IdentityFile ~/.ssh/path_to_your_work_assembla_key

#BitBucket work account

Host wrkbitbucket
    HostName bitbucket.org
    IdentityFile ~/.ssh/path_to_your_work_assembla_key



3) Use aliases for git urls like this: git@wrkgithub:username/projectnsme.git instead git@github.com:username/projectnsme.git