For example: you have a repo in private organization myteamprivate
with url git@github.com:myteamprivate/repo-api.git
1. Create ssh key on your machine
1
| $ ssh-keygen -t rsa -C "your_email@youremail.com"
|
- Your email can be the same email with other accounts
- File name format:
id_rsa_[private organization]
2. Modify ssh config
Then add below config
1
2
3
4
5
6
7
| # "myteam" can be whatever, it'll be used when you clone repo
Host github.com-myteam
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_myteamprivate
IdentitiesOnly yes
User git
|
3. Copy public key and paste it in Github SSH Key
1
| $ cat ~/.ssh/id_rsa_myteamprivate.pub | pbcopy
|
Then go to Github setting and paste it in Key
input
Now you can clone the repo with SSH
1
2
| $ git clone git@github.com-myteam:myteamprivate/repo-api.git
# "myteam" here is what you defined in ssh config Host
|
Note: you can change your config for repo by
1
2
| $ git config user.name "Sanh Doan"
$ git config user.email "dpsanh@troodonlabs.com"
|
Note: If the ssh-key not auto added, you need to add ssh-agent manually
1
2
| $ eval $(ssh-agent)
$ ssh-add ~/.ssh/id_rsa_myteamprivate
|