一臺(tái)電腦配置多個(gè)ssh key連接不同的倉庫時(shí),需要配置ssh config,進(jìn)行 key和host的綁定。
config文件的路徑為:~/.ssh/config
Host git.bbdops.com
Hostname git.bbdops.com
IdentityFile ~/.ssh/id_rsa
PreferredAuthentications publickey
User panhui
Port 51668
Host github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa_github
PreferredAuthentications publickey
User git
如上的配置:一個(gè)git.bbdops.com,一個(gè)github.com。
Host
Host是可以隨意起名的,但是需要注意的是,如果Host命名為github而非github.com,那么在測試key時(shí)需要ssh -T git@github,而非git -T git@github.com。Hostname
遠(yuǎn)程倉庫實(shí)際的域名,或IP。IdentityFile
生成時(shí)命名的秘鑰文件,我這里git.bbdops.com對應(yīng)id_rsa;github.com對應(yīng)id_rsa_github。Port
默認(rèn)缺省是22端口,像我們公司的gitlab端口更改過,就需要在這里特別指定一下,否則ssh會(huì)以22端口去連接而被server端拒絕。
關(guān)于ssh key配置更多詳細(xì)內(nèi)容可參考 https://blog.csdn.net/qq774232122/article/details/52138380