How to accessing multiple Git accounts from the same computer using different private keys?
Random | 08 Apr 2015
Tags: github, account
In order to access multiple github accounts from one computer you need to :
- generate ssh keys
- add ssh keys to your github account
- create a configuration file to manage the separate keys
- update stored identities
Step 1 - Generating SSH keys:
cd ~/.ssh ssh-keygen -t rsa -C "[email associated with your github account #1]" # save it as id_rsa_git_account1 when prompted ssh-keygen -t rsa -C "[email associated with your github account #2]" # save it as id_rsa_git_account2 when prompted
As the result of executing these commands, the following files will be generated:
Step 2 - Adding ssh keys to your github account
Using this command you can copy the key to your clipboard:
pbcopy < ~/.ssh/id_rsa_git_account1.pub
Now as the key is in your account, all you have to do is to open your github account and:
- Click on Account Settings
- Click "SSH Keys" -> "Add SSH Key"
- Paste your key into key field and add a relevant title
- Click "Add key" then enter your Github password to confirm.
Step 3 - Create a configuration file to manage the separate keys
- Navigate to ~/.ssh/
- touch config
- Enter the configuration to the config file:
IdentityFile ~/.ssh/id_rsa_git_account1# github Account2
Step 4 - Update Stored Identities:
Add new keys:
Test to make sure new keys are stored
Teting Push / Pull
$ git ini
$ git add .
$ git commit -am "first commit"
$ git remote add origin git@account1:githubPersonal/test-personal.git
$ git push origin master