- Create ssh keys using the following command:
ssh-keygen -t rsa -C "xxx@youremail.com"
ssh-keygen -t rsa -C "yyy@youremail.com"
Each email corresponds to a different github account.
It is also possible to have repository specific deploy keys.
If a repository does not have its own deploy key, access to it
is given by the repo's github account ssh keys.
- Two pairs of ssh keys are created in ~/.ssh dir:
~/.ssh/id_rsa_xxx
~/.ssh/id_rsa_yyy
with names chosen in step 1.
- Add keys using:
-
ssh-add ~/.ssh/id_rsa_xxx
ssh-add ~/.ssh/id_rsa_yyy
This adds adds your RSA identities to the authentication agent,
ssh-agent, a program for storing private keys used for public key
authentication.
-
Use
ssh-add -l to list all added keys
- Associate the keys with the Github accounts according to instructions on:
- https://help.github.com/articles/generating-ssh-keys/
- On your local machine configure GitHub settings. Add configuration to ~/.ssh/config:
#xxx account Host github.com-xxx HostName github.com User git IdentityFile ~/.ssh/id_rsa_xxx #yyy account Host github.com-yyy HostName github.com User git IdentityFile ~/.ssh/id_rsa_yyy
Hosts
github.com-xxx,
github.com-yyy are arbitrary names,
that help distinguish the two accounts
- Test authorization to connect to GitHub:
- ssh -T git@github.com-xxx
- ssh -T git@github.com-yyy
- Clone a repository, using the relevant Host alias:
- git clone git@github.com-xxx:xxx/repo_aaa.git [aaa_dir]
- The general git configuration can be found in ~/.gitconfig. The entries can be either added manually or through git commands:
- git config --global ... (user.email, user.name etc)
- For repository specific configuration (repository's .git/config):
- cd repo_aaa (or aaa_dir)
git config user.name "X XXX"
git config user.email "xxx@gmail.com"
git remote set-url origin git@github.com-xxx:xxx/repo_aaa.git
This will result in the following setup:
[remote "origin"] url = git@github.com-xxx:xxx/repo_aaa.git
where
github.com-xxx corresponds to the Host value in step 6
xxx
corresponds to the github username
NOTE
- Configuration, that is present only in the global git config file ~/.gitconfig (setup either through the git config --global comand or manually) and not overriden by cloned repository's .git/config setup, will be used.
- Setting up the [remote "origin"] block in the global configuration, results in a bizarre situation, where one can be cloning an empty (well, any) github repo, and the local clone will have an unexpected content (corresponding to the remote origin url, ie a different repo).
No comments:
Post a Comment
Note: only a member of this blog may post a comment.