一臺電腦配置多個(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