Windows电脑多个SSH Key管理.md

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

环境

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

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

  1. 注册好 Github 账号,其中 Email 为 987654321@qq.com
  2. 用支付宝/淘宝账号登录 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
    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 git@github.com

阿里云

1.在 Git bash 输入命令

ssh-keygen -t rsa -C "987654321@163.com"

2.执行结果

3.拷贝公钥

  • 方法和 Github 中相同,目标文件变为 id_rsa_aliyun_code.pub

4.新增 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

参考博客

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

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

  3. 阿里云代码 SSH

posted @ 2020-02-08 23:47  极客子羽  阅读(837)  评论(1编辑  收藏  举报