Advertisement
Guest User

Untitled

a guest
Apr 28th, 2019
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. 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.
  2.  
  3. Let's say you already have 2 keys configured as follows:
  4. ```
  5. ~/.ssh/id_rsa # personal
  6. ~/.ssh/id_rsa_work # work
  7. ```
  8. And they're both loaded in the ssh-agent
  9. ```
  10. $ ssh-add -l
  11. ... .ssh/id_rsa (RSA)
  12. ... .ssh/id_rsa_work (RSA)
  13. ```
  14.  
  15. Update your `~/.ssh/config` so that your work key uses an alias for the host.
  16. ```
  17. # Personal
  18. Host *
  19. AddKeysToAgent yes
  20. UseKeychain yes
  21. IdentityFile ~/.ssh/id_rsa
  22.  
  23. # Work
  24. Host work-github.com
  25. HostName github.com
  26. AddKeysToAgent yes
  27. UseKeychain yes
  28. IdentityFile ~/.ssh/id_rsa_work
  29. ```
  30.  
  31. Now when you clone repositories, you'll need to specify them with the `work-github.com` host name.
  32. ```
  33. git clone git@github.com:workorg/workrepo.git # wrong
  34. git clone git@work-github.com:workorg/workrepo.git # right
  35. ```
  36.  
  37. If you find that annoying or hard to remember, you can set a global git config like so:
  38. ```
  39. git config --global url."git@work-github.com:workorg".insteadOf git@github.com:workorg
  40. ```
  41.  
  42. Now you can do:
  43. ```bash
  44. ~ $ git clone git@github.com:work/workrepo.git
  45. ~ $ cd workrepo
  46. ~/workrepo $ git remote -v
  47. origin git@work-github.com:work/workrepo.git (fetch)
  48. origin git@work-github.com:work/workrepo.git (push)
  49.  
  50. ~ $ git clone git@github.com:notwork/notworkrepo.git
  51. ~ $ cd notworkrepo
  52. ~/notworkrepo $ git remote -v
  53. origin git@github.com:notwork/notworkrepo.git (fetch)
  54. origin git@github.com:notwork/notworkrepo.git (push)
  55. ```
  56. The remotes for your existing work repositories will automatically be updated too!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement