問題背景
工作使用的時候,使用公司的gitlab倉庫,倉庫網域名稱為gitlab.biz.domain,員工賬號為[email protected];
維護個人專案的時候,使用github倉庫,倉庫網域名稱為github.com,個人賬號為[email protected];
兩個倉庫都通過ssh-key驗證,本地git提交**時,可以根據需要,使用不同的key,提交至不同的倉庫。
解決方案
本地生成兩套 ssh-key,將 public key 分別新增至相應的倉庫,通過配置檔案 config,實現提交至不同網域名稱倉庫時,自動使用不同的 private key 進行身份驗證。
實現步驟
1、生成兩套 ssh-key 金鑰對:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa.gitlab -c "[email protected]"
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa.github -c "[email protected]"
-t :表示金鑰型別
-b:指定金鑰長度(預設2046)
-f:指定金鑰檔名
-c:新增金鑰注釋
2、設定配置檔案:
在~/.ssh目錄下建立乙個 config 檔案,同時,修改檔案操作許可權:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
修改 config 配置檔案內容,如下:
host gitlab.biz.domain
identityfile ~/.ssh/id_rsa.gitlab
host github.com
identityfile ~/.ssh/id_rsa.github
此時,使用ssh登入時,將根據網域名稱,選擇不同的私鑰進行鑑權驗證。 git 的ssh key 多個ssh key問題
背景 在設定github的時候,需要設定ssh key。備份當前的key,生成新的key用於登陸github。問題 原先得key不能用了。線上的機器 clone下來的project中origin預設內容是該project在伺服器端的目錄,你是沒有許可權往別人的project裡直接push commi...
Git配置多個SSH Key
之前週末在家使用github建立ssh key進行blog的提交,但是第二天在用公司,使用公司的gitlab提交 時發現賬號是我github的賬號,我想肯定是github生成的ssh key把之前我公司gitlab的ssh key給覆蓋了 檢視我所有ssh key cd ssh ls github ...
git 配置多個SSH Key
專案託管的倉庫多了,使用的賬號多了,自然用到的key就不同了,比如gitlab,bitbucket,github,公司的code倉庫等,所以管理好key很重要。1,生成乙個公司用的ssh key ssh keygen t rsa c 1email company.com f ssh id rsa2,...