在 github 上多帳號與多組 ssh key 使用
Steps
1. create new ssh pair
ssh-keygen -t rsa -C '[email protected]' -f id_rsa_mygit
2. edit ~/.ssh/config
# company github account
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# my github account
Host github-mygit
HostName github.com
IdentityFile ~/.ssh/id_rsa_mygit
IdentitiesOnly yes
3. add into ssh-agent
ssh-add -D && ssh-add -L # reset all ssh keys, optional
# add them into ssh-agent
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_mygit
# ...other keys if you want
# test connection
ssh -T [email protected]
ssh -T git@github-mygit
4. clone your git project
git clone git@github-mygit:xxxxx/xxxxx.git
About submodule
修改其於 .git/modules/<folder>/config
裡的設定
...
[remote "origin"]
url = [email protected]:xxxxx/xxxxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
這樣就可以正常使用不同 github 帳號的 ssh key 了
Reference
發佈時間
2020-12-10