Guest User

Untitled

a guest
Aug 12th, 2018
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. 3 steps:
  2. - Create multi ssh key
  3. - Add config key
  4. - Change host to using the right key
  5.  
  6. Step 1: generate ssh key. Ex:
  7.  
  8. ssh-keygen -t rsa -f ~/.ssh/ducmb_ducnn01 -C “ducnn01@gmail.com"
  9. ssh-keygen -t rsa -f ~/.ssh/ducmb_ngocducdev -C "ngocducdev@gmail.com"
  10.  
  11. Add the public key to each account.
  12.  
  13. Step 2: map keys with hosts on .ssh/config file.
  14.  
  15. Host home.projects
  16. User git
  17. Hostname gitlab.com
  18. PreferredAuthentications publickey
  19. IdentitiesOnly yes
  20. IdentityFile ~/.ssh/ducmb_ducnn01
  21.  
  22. Host work.projects
  23. User git
  24. Hostname bitbucket.org
  25. PreferredAuthentications publickey
  26. IdentitiesOnly yes
  27. IdentityFile ~/.ssh/ducmb_ngocducdev
  28.  
  29. Step 3: Change the host name on the remote url:
  30.  
  31. ssh://git@hostname:<user_name>/<repo_name>.git
  32.  
  33. Ex:
  34. git clone git@gitlab.com:ducnn01/rider.git —> git clone git@home.projects:ducnn01/rider.git
  35. git clone git@bitbucket.org:ngocducdev/rider.git —> git clone git@work.projects:ngocducdev/rider.git
  36.  
  37.  
  38.  
  39. // ———————————————————
  40. $ cd ~/.ssh
  41.  
  42. Create Default key if it doesn't exist
  43. $ ssh-keygen -t rsa
  44. $ ssh-add ~/.ssh/id_rsa
  45.  
  46. Creating other keys
  47. $ ssh-keygen -t rsa -C "companyName" -f "companyName"
  48. $ ssh-add ~/.ssh/companyName
  49.  
  50. Create SSH Config
  51.  
  52. Host personal.project
  53. Hostname bitbucket.org
  54. User <personal_username>
  55. IdentityFile ~/.ssh/id_rsa
  56. Host work.project
  57. Hostname bitbucket.org
  58. User <work_username>
  59. IdentityFile ~/.ssh/<other_key>
  60.  
  61.  
  62. Set up Git remote origin for multiple accounts
  63.  
  64. Set up a remote origin with your personal account as you normally would:
  65. $ git remote add origin ssh://git@personal.project:<user_name>/<repo_name>.git
  66.  
  67. Set up your work account using the Host alias
  68. $ git remote add origin ssh://git@<alias>:<user_name>/<repo_name>.git
  69.  
  70.  
  71. Example:
  72. $ git remote add origin ssh://git@work.project/<user_name>/<repo_name>.git
Add Comment
Please, Sign In to add comment