筆者偏在阿里雲,Github,開源中國上均存放一些私有項目代碼,因此需要再Windows電腦上配置多個SSH Key
環境
- 操作系統:windows 7
- Git
提示:Git 安裝后就可以使用 Git bash ,接下來的命令都在 Git bash 中輸入和執行
- 注冊好 Github 賬號,其中 Email 為 987654321@qq.com
- 用支付寶/淘寶賬號登錄 https://code.aliyun.com ,在設置->個人設置頁面看到郵箱為 987654321@163.com
Github
1.打開 Git bash
2.輸入命令
ssh-keygen -t rsa -C "987654321@qq.com"
3.執行結果
4.拷貝公鑰
- 方法一:在 Git Bash 中輸入命令拷貝文件內容到剪切板:
clip < ~/.ssh/id_rsa_github.pub
- 方法二:從文件中拷貝
進入 C:\Users\{你的用戶名}.ssh\ ,用記事本打開 id_rsa_github.pub,拷貝文件中所有內容
5.添加復制的公鑰到 Github 中
-
首先,登錄 https://www.github.com ,在右上角打開彈出框,選擇 Settings
-
在 SSH and GPG keys 打開 New SSH Key
-
粘貼剪切板中公鑰並 Add SSH Key:
6.在 .ssh 目錄下創建 config 配置文件
輸入以下配置信息:
# 配置github 的key
Host github.com
HostName github.com
User git
IdentityFile C:\Users\Administrator\.ssh\id_rsa_github
7.命令測試:
ssh -T git@github.com
阿里雲
1.在 Git bash 輸入命令
ssh-keygen -t rsa -C "987654321@163.com"
2.執行結果
3.拷貝公鑰
- 方法和 Github 中相同,目標文件變為 id_rsa_aliyun_code.pub
4.新增 SSH 公鑰
-
首先,登錄 https://code.aliyun.com , 然后點擊 設置
-
點擊“增加 SSH 密鑰”
-
新增密鑰
5.編輯 config
新增以下信息
# 配置 code.aliyun 的 key
Host code.aliyun.com
HostName code.aliyun.com
User git
IdentityFile C:\Users\Administrator\.ssh\id_rsa_aliyun_code
6.測試
ssh -T git@code.aliyun.com