Host github-A HostName github.com User git IdentityFile /Users/xxx/.ssh/id_rsa_A IdentitiesOnly yes Host github-B HostName github.com User git IdentityFile /Users/xxx/.ssh/id_rsa_B IdentitiesOnly yes
config文件保存不一樣host的所使用的ssh密鑰。html
你在github有多個帳號,當push代碼時須要使用不一樣的ssh-key,可是git remote -v看到默認都是git@github.com:xxxRepo/xxx.git(git是用戶名,github.com是Host名)。這樣一來,使用的是同一份配置,同一份私鑰。git
如上,兩份不一樣Host的配置。而後在repo下,git remote set-url origin git@github-A:repoA/xxx.git 就能夠區分開了github
Host
github-A
。Host
必須跟repo的hostname
保持一致,也就是git到時候會用本身repo的hostname
來ssh配置文件裏面找是否是有對應的Host
,找到了就使用該配置,具體訪問的域名會採用HostName
Hostname
Host
對應的具體域名User git
IdentityFile /Users/xxx/.ssh/id_rsa.github
IdentitiesOnly yes
yes
,具體意義能夠參考討論。配置文件中能夠忽略此項。
做者:陽臺的晾衣架
連接:https://www.jianshu.com/p/45201d18cc7c
來源:簡書
ssh