天天看點

IDEA 中git使用非預設ssh用戶端進行登入IDEA 中git使用非預設ssh用戶端進行登入

IDEA 中git使用非預設ssh用戶端進行登入

一、建立多對ssh秘鑰對

  1. Mac 版在終端中 Windows 版 在git bash 中建立
  2. 使用ssh-keygen 建立秘鑰對 -t 指定秘鑰類型 -C 為備注 一般使用郵箱為區分
  3. 生成的檔案 Mac ~/.ssh/ 目錄下 Windows 一般在執行目錄下
  4. 重複以上步驟生成多對秘鑰即可
# ssh-keygen -t rsa -C "[email protected]" 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/alan/.ssh/id_rsa): test_rsa  ---生成key的名稱
Enter passphrase (empty for no passphrase):
Enter same passphrase again:   輸入兩邊密碼 或者直接回車無密碼           

二、設定非預設位置的秘鑰在git中使用

  1. 使用者目錄下的.ssh檔案夾中建立檔案 config Mac 在終端輸入 cd ~/.ssh 即可 Windows 自行了解
  2. 編輯config檔案
Host git.xxx.com
     HostName 你要代理的域名、ip位址等
     IdentityFile 絕對路徑的 test_rsa           

三、在IDEA的git中應用

  1. 将git連接配接位址由 [email protected]:xxx/xxx.git 更改為 [email protected]:xxx/xxx.git
  2. 将test_rsa.pub 内容添加到git SSH公鑰庫
  3. 更新git url指令如下
# git remote set-url origin  新位址           

繼續閱讀