有時候咱們可能須要在同一臺電腦上配置多個SSH Key
,好比公司項目使用的是GitHub
,我的開發用的是碼雲Gitee
。這個時候咱們可能須要有兩個SSH Key
,怎麼配置呢?git
假設你以前已經生成了一個GitHub
的SSH Key
,能夠用命令cat ~/.ssh/id_rsa.pub
查看已經生成的SSH Key
:github
複製命令ssh-keygen -t rsa -C 'xxxxx@youremail.com' -f ~/.ssh/gitee_id_rsa
生成一個Gitee
的SSH Key
,一路回車就能夠了(記得把郵箱改爲你本身的)。能夠看到.ssh
文件夾下面多了兩個文件。服務器
使用命令cat ~/.ssh/gitee_id_rsa.pub
查看Gitee
的SSH Key
,複製ssh
開頭的那一串公鑰,添加到Gitee
倉庫。ssh
使用命令touch ~/.ssh/config
,在~/.ssh
文件夾下添加config文件,能夠看到文件夾下面多了一個config文件。測試
右鍵使用記事本打開,複製如下信息添加到config文件保存,其中Host
和HostName
填寫git服務器的域名,IdentityFile
填寫私鑰的路徑。spa
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitee_id_rsa # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
使用如下命令分別測試GitHub
和Gitee
,查看SSH Key
是否添加成功。3d
ssh -T git@gitee.com ssh -T git@github.com
看到如下的提示,就表示添加成功,能夠拉取、推送代碼了。code