Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If you are using your work and personal github accounts locally, you'll need a little more setup to have both ssh keys playing nicely together.
- Let's say you already have 2 keys configured as follows:
- ```
- ~/.ssh/id_rsa # personal
- ~/.ssh/id_rsa_work # work
- ```
- And they're both loaded in the ssh-agent
- ```
- $ ssh-add -l
- ... .ssh/id_rsa (RSA)
- ... .ssh/id_rsa_work (RSA)
- ```
- Update your `~/.ssh/config` so that your work key uses an alias for the host.
- ```
- # Personal
- Host *
- AddKeysToAgent yes
- UseKeychain yes
- IdentityFile ~/.ssh/id_rsa
- # Work
- Host work-github.com
- HostName github.com
- AddKeysToAgent yes
- UseKeychain yes
- IdentityFile ~/.ssh/id_rsa_work
- ```
- Now when you clone repositories, you'll need to specify them with the `work-github.com` host name.
- ```
- git clone git@github.com:workorg/workrepo.git # wrong
- git clone git@work-github.com:workorg/workrepo.git # right
- ```
- If you find that annoying or hard to remember, you can set a global git config like so:
- ```
- git config --global url."git@work-github.com:workorg".insteadOf git@github.com:workorg
- ```
- Now you can do:
- ```bash
- ~ $ git clone git@github.com:work/workrepo.git
- ~ $ cd workrepo
- ~/workrepo $ git remote -v
- origin git@work-github.com:work/workrepo.git (fetch)
- origin git@work-github.com:work/workrepo.git (push)
- ~ $ git clone git@github.com:notwork/notworkrepo.git
- ~ $ cd notworkrepo
- ~/notworkrepo $ git remote -v
- origin git@github.com:notwork/notworkrepo.git (fetch)
- origin git@github.com:notwork/notworkrepo.git (push)
- ```
- The remotes for your existing work repositories will automatically be updated too!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement