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密鑰。
使用場景:
問題
你在github有多個賬號,當push代碼時需要使用不同的ssh-key,但是git remote -v看到默認都是git@github.com:xxxRepo/xxx.git(git是用戶名,github.com是Host名)。這樣一來,使用的是同一份配置,同一份私鑰。
解決方法:
如上,兩份不同Host的配置。然后在repo下,git remote set-url origin git@github-A:repoA/xxx.git 就可以區分開了
config配置含義
-
Host
用來指定該key的Host名字,此處必須使用本地repo的hostnamegithub-A
。
Host
必須跟repo的hostname
保持一致,也就是git到時候會用自己repo的hostname
來ssh配置文件里面找是不是有對應的Host
,找到了就使用該配置,具體訪問的域名會采用HostName
-
Hostname
此處指定Host
對應的具體域名 -
User git
說明該配置的用戶得是git -
IdentityFile /Users/xxx/.ssh/id_rsa.github
這行最為關鍵,指定了該使用哪個ssh key文件,這里的key文件一定指的是私鑰文件。 -
IdentitiesOnly yes
配置為yes
,具體意義可以參考討論。配置文件中可以忽略此項。
作者:陽台的晾衣架
鏈接:https://www.jianshu.com/p/45201d18cc7c
來源:簡書