本地配置多個ssh,不同賬號,連線多個倉庫
阿新 • • 發佈:2022-05-12
生成ssh 公私鑰
1.生成倉庫a的公私鑰,假設郵箱為[email protected]:
在 git bash ./ssh 目錄下輸入如下命令:
ssh
-keygen -t rsa -C
"[email protected]"
-f ~/.
ssh
/a_id-rsa
.ssh目錄下生成檔案如下:
2.將 .pub檔案中的內容全部複製到git中的ssh的key上,add
3.用同樣方法生成倉庫b的公私鑰,假設郵箱為[email protected]
ssh
-keygen -t rsa -C
"[email protected]"
-f ~/.
ssh
/b_id-rsa
ssh agent 新增多個私鑰
預設只讀取 id_rsa,為了讓 SSH 識別新的私鑰,需要將新的私鑰加入到 SSH agent 中
# 檢視已經新增的私鑰
ssh
-add -l
3072 SHA256:xxxxxxxxxx [email protected] (RSA)
$
ssh
-agent
bash
$
ssh
-add ~/.
ssh
/github_id_rsa
$
ssh
-add ~/.
ssh
/gitlabnei_id_rsa
配置config 檔案
手動建立config檔案,不需要字尾
config 中放入如下內容,儲存Host git.a.com //git源 IdentityFile ~/.ssh/a_id-rsa //你自己的a的ssh-key檔名(沒有.pub字尾的檔案) User a //你的a的賬號 Host git.b.com // IdentityFile ~/.ssh/b_id-rsa //你自己的b的ssh-key檔名(沒有.pub字尾的檔案) User b //你的b的賬號
參考:http://www.iis7.com/a/nr/wz/202108/49284.html