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不一樣帳號下的不一樣項目到本地咯

相關文章
相關標籤/搜索