同一臺機器配置多個SSH,同時綁定Coding,Github和Gitee

Git的配置

$git config --global user.name "xxx"           //配置用戶名
$git config --global user.email "xxx"          //配置註冊郵箱
$git config --global --list                //查看當前用戶(global)配置

創建多個公鑰

打開Git Bash,進入~/.ssh目錄

生成 github_rsa公鑰

$ssh-keygen -t rsa -b 4096 -C "[email protected]"

在提示Enter passphrase 和 Enter same passphrase again : 都按回車
在提示“Enter file in which to save the key” 時輸入 github_rsa

生成 gitee_rsa公鑰

$ssh-keygen -t rsa -C "[email protected]"

在提示Enter passphrase 和 Enter same passphrase again : 都按回車
在提示“Enter file in which to save the key” 時輸入Gitee.rsa

生成 coding_rsa公鑰

$ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"

在提示Enter passphrase 和 Enter same passphrase again : 都按回車
在提示“Enter file in which to save the key” 時輸入 coding_rsa

查看.ssh目錄下生成的文件

在Bash終端ls查看目錄下的文件

在資源管理器查看

添加和編輯配置文件config

  1. 在~/.ssh目錄下新建一個config文件
touch ~/.ssh/config

  1. 在config文件中添加如下配置內容:
#coding
Host e.coding.net
HostName e.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/coding_rsa
User cyiiot

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_rsa
User cyiiot

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa
User cyiiot

綁定Coding,Github和Gitee的SSH

綁定Coding SSH

  1. 打開coding_rsa.pub,將裏面的內容全部複製
  2. 登錄CODING,點擊右上角【個人設置】,選擇菜單【SSH公鑰】,點擊【新增公鑰】按鈕。

  1. 將第一步中複製的內容填寫到【公鑰內容】一欄,公鑰名稱按需填寫即可
  2. 設定公鑰有效期,可選擇具體日期或設置永久有效

  1. 點擊【添加】,然後輸入賬戶密碼即可成功添加公鑰
  2. 完成後在命令行測試,首次建立鏈接會要求信任主機。命令 ssh -T [email protected]

綁定GitHub SSH

  1. 打開github_rsa.pub,將裏面的內容全部複製
  2. 登錄GitHub,在任何頁面的右上角點擊個人資料照片,然後點擊 【Settings】

  1. 在用戶設置邊欄中,點擊【SSH and GPG keys】

  1. 點擊【New SSH key】,新建SSH密鑰

  1. 在“Title”字段中,爲新密鑰添加一個描述性標籤。
  2. 將從github_rsa.pub文件中複製出來的密鑰 ,粘貼在“Key”字段中。

  1. 點擊【Add SSH key】,然後輸入賬戶密碼即可成功添加公鑰

  1. 完成後在命令行測試,首次建立鏈接會要求信任主機。命令 ssh -T [email protected]

綁定Gitee SSH

  1. 打開gitee_rsa.pub,將裏面的內容全部複製
  2. 登錄Gitee,在任何頁面的右上角點擊個人資料照片處,點擊【設置】

  1. 點擊左欄【安全設置】下的【SSH公鑰】
  2. 將前面複製的公鑰,粘貼在【添加公鑰】下的“公鑰”字段中
  3. 點擊【確定】,然後輸入賬戶密碼即可成功添加公鑰

  1. 完成後在命令行測試,首次建立鏈接會要求信任主機。命令 ssh -T [email protected]

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章