Window同一电脑配置多个git公钥

前言

配置多个本地ssh-key以前,先初始化下GIt环境哦!html

能够参照:http://www.javashuo.com/article/p-rmnuojra-cv.htmlgit

执行前两步就好啦github

 

本地生成两个ssh-key

ssh-keygen -t rsa -C "123456@qq.com" -f ~/.ssh/polo_rsa
ssh-keygen -t rsa -C "123457@qq.com" -f ~/.ssh/polo1_rsa

 

Github添加ssh-key

将生成的两个公钥添加到Github中;能够将其中一个公钥添加到帐号A,另外一个公钥添加到帐号B,实如今本地可同时提交不一样仓库的代码ssh

(如何添加ssh-key请查看http://www.javashuo.com/article/p-mkmxewio-co.htmlide

 

生成本地多个公钥的配置文件

在本地 C:\Users\用户名\.ssh 文件夹中生成 config 文件,无需后缀,填入如下内容字体

# 添加config配置文件

# 文件内容以下:
# home
Host polo.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/polo_rsa
    User polo

# work
Host polo1.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/polo1_rsa
    User polo1  

# 配置文件参数
# Host : Host能够看做是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件
# HostName : 要登陆主机的主机名
# User : 登陆名
# IdentityFile : 指明上面User对应的identityFile路径

注意点

  • 红色字体是须要本身根据本身的状况改变的
  • IdentityFile后面的文件名是要填写你生成的公钥文件名,以下图所示

 

验证是否成功

输入如下命令就行啦spa

ssh -T git@{Host}
ssh -T git@{Host}

Host是须要根据本身的定义填写的哈,你在config文件中的两个Host写了啥这里就写啥就好啦,以下图所示哦code

 

clone不一样仓库代码

本地单个公钥时,执行git clone命令以下htm

git@github.com:用户名/项目名.git

当有多个公钥时,本地clone项目时,须要修改命令blog

git@polo.github.com:用户名1/项目名1.git
git@polo1.github.com:用户名2/项目名2.git

这样就能够clone不一样帐号下的不一样项目到本地咯

相关文章
相关标签/搜索