最近在工作的電腦上需要使用不同的Github account來存取不同的Repo,在踩了一些雷後終於完成設定,現在可以自由的切換account來存取不同的Repo了。
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_a
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_b
$ eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github_a
ssh-add ~/.ssh/github_b
vim ~/.ssh/config
Host gtihub_q
HostName github.com
AddKeysToAgent yes
User git
UseKeychain yes
IdentityFile ~/.ssh/github_a
Host github_b
HostName github.com
AddKeysToAgent yes
User git
UseKeychain yes
IdentityFile ~/.ssh/github_b
ssh -T git@github_a
git clone git@github_a:XXXXX/XXXXX.git
這邊滿重要的是你在clone 時去修改repo給你的預設指令
將git clone [email protected]:XXXXX/XXXXX.git
改成git clone git@github_a:XXXXX/XXXXX.git
origin [email protected]:xxxxx/xxxxx.git (fetch)
origin [email protected]:xxxxx/xxxxx.git (push)
改成
origin git@github_a:xxxxx/xxxxx.git (fetch)
origin git@github_a:xxxxx/xxxxx.git (push)
這樣就可以不用在一直切帳號來存取不同的repo了。