Windows电脑多个SSH Key管理.md

笔者偏在阿里云,Github,开源中国上均存放一些私有项目代码,因此需要再Windows电脑上配置多个SSH Key

环境

  1. 操作系统:windows 7
  2. Git

    提示:Git 安装后就可以使用 Git bash ,接下来的命令都在 Git bash 中输入和执行

  3. 注册好 Github 账号,其中 Email 为 [email protected]
  4. 用支付宝/淘宝账号登录 https://code.aliyun.com ,在设置->个人设置页面看到邮箱为 [email protected]

Github

1.打开 Git bash
2.输入命令

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

3.执行结果

4.拷贝公钥

  • 方法一:在 Git Bash 中输入命令拷贝文件内容到剪切板:
clip < ~/.ssh/id_rsa_github.pub
  • 方法二:从文件中拷贝
    进入 C:\Users\{你的用户名}.ssh\ ,用记事本打开 id_rsa_github.pub,拷贝文件中所有内容

5.添加复制的公钥到 Github 中

  • 首先,登录 https://www.github.com ,在右上角打开弹出框,选择 Settings
    Github 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 [email protected]

阿里云

1.在 Git bash 输入命令

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

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 [email protected]

参考博客

  1. 同一台电脑关于多个SSH KEY管理

  2. Windows下Git多账号配置,同一电脑多个ssh-key的管理

  3. 阿里云代码 SSH

猜你喜欢

转载自www.cnblogs.com/zaid/p/12285765.html