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