同一臺機器配置多個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
- 在~/.ssh目錄下新建一個config文件
touch ~/.ssh/config
- 在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
- 打開coding_rsa.pub,將裏面的內容全部複製
- 登錄CODING,點擊右上角【個人設置】,選擇菜單【SSH公鑰】,點擊【新增公鑰】按鈕。
- 將第一步中複製的內容填寫到【公鑰內容】一欄,公鑰名稱按需填寫即可
- 設定公鑰有效期,可選擇具體日期或設置永久有效
- 點擊【添加】,然後輸入賬戶密碼即可成功添加公鑰
- 完成後在命令行測試,首次建立鏈接會要求信任主機。命令
ssh -T [email protected]
綁定GitHub SSH
- 打開github_rsa.pub,將裏面的內容全部複製
- 登錄GitHub,在任何頁面的右上角點擊個人資料照片,然後點擊 【Settings】
- 在用戶設置邊欄中,點擊【SSH and GPG keys】
- 點擊【New SSH key】,新建SSH密鑰
- 在“Title”字段中,爲新密鑰添加一個描述性標籤。
- 將從github_rsa.pub文件中複製出來的密鑰 ,粘貼在“Key”字段中。
- 點擊【Add SSH key】,然後輸入賬戶密碼即可成功添加公鑰
- 完成後在命令行測試,首次建立鏈接會要求信任主機。命令
ssh -T [email protected]
綁定Gitee SSH
- 打開gitee_rsa.pub,將裏面的內容全部複製
- 登錄Gitee,在任何頁面的右上角點擊個人資料照片處,點擊【設置】
- 點擊左欄【安全設置】下的【SSH公鑰】
- 將前面複製的公鑰,粘貼在【添加公鑰】下的“公鑰”字段中
- 點擊【確定】,然後輸入賬戶密碼即可成功添加公鑰
- 完成後在命令行測試,首次建立鏈接會要求信任主機。命令
ssh -T [email protected]