Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3 steps:
- - Create multi ssh key
- - Add config key
- - Change host to using the right key
- Step 1: generate ssh key. Ex:
- ssh-keygen -t rsa -f ~/.ssh/ducmb_ducnn01 -C “ducnn01@gmail.com"
- ssh-keygen -t rsa -f ~/.ssh/ducmb_ngocducdev -C "ngocducdev@gmail.com"
- Add the public key to each account.
- Step 2: map keys with hosts on .ssh/config file.
- Host home.projects
- User git
- Hostname gitlab.com
- PreferredAuthentications publickey
- IdentitiesOnly yes
- IdentityFile ~/.ssh/ducmb_ducnn01
- Host work.projects
- User git
- Hostname bitbucket.org
- PreferredAuthentications publickey
- IdentitiesOnly yes
- IdentityFile ~/.ssh/ducmb_ngocducdev
- Step 3: Change the host name on the remote url:
- ssh://git@hostname:<user_name>/<repo_name>.git
- Ex:
- git clone git@gitlab.com:ducnn01/rider.git —> git clone git@home.projects:ducnn01/rider.git
- git clone git@bitbucket.org:ngocducdev/rider.git —> git clone git@work.projects:ngocducdev/rider.git
- // ———————————————————
- $ cd ~/.ssh
- Create Default key if it doesn't exist
- $ ssh-keygen -t rsa
- $ ssh-add ~/.ssh/id_rsa
- Creating other keys
- $ ssh-keygen -t rsa -C "companyName" -f "companyName"
- $ ssh-add ~/.ssh/companyName
- Create SSH Config
- Host personal.project
- Hostname bitbucket.org
- User <personal_username>
- IdentityFile ~/.ssh/id_rsa
- Host work.project
- Hostname bitbucket.org
- User <work_username>
- IdentityFile ~/.ssh/<other_key>
- Set up Git remote origin for multiple accounts
- Set up a remote origin with your personal account as you normally would:
- $ git remote add origin ssh://git@personal.project:<user_name>/<repo_name>.git
- Set up your work account using the Host alias
- $ git remote add origin ssh://git@<alias>:<user_name>/<repo_name>.git
- Example:
- $ git remote add origin ssh://git@work.project/<user_name>/<repo_name>.git
Add Comment
Please, Sign In to add comment