一臺電腦的git使用兩個github賬號(生成多個ssh key)
前情提要:
要是想搭建多個部落格,需要多個郵箱,以註冊多個Github賬號(一個GitHub賬號只能建一個與賬號名相同的倉庫)。
並且在一個電腦上預設生成的ssh密匙名為id_rsa,想要給每個部落格申請一個ssh密匙,需要進行重新命名密匙等配置操作。
本教程可以解決以上問題,小夥伴們要是想在一個電腦上操作多個部落格,可配合另一個Hexo+Github搭建教程使用。
地址為
本教程舉例生成兩個ssh密匙,(生成多個與此原理相同)。
1.多個Github賬號的註冊和部落格其他配置
參見教程:https://blog.csdn.net/qq_41979043/article/details/83046278
2.生成兩個ssh密匙
ssh-keygen -t rsa -C "郵箱號[email protected]"
ssh-keygen -t rsa -C "郵箱號 [email protected]"
①如下圖操作:
ps:要在~/.ssh路徑下執行命令列。
新增第1個密匙:重新命名為id_rsa_messi1002。
新增第2個ssh密匙:重新命名為id_rsa_read1002。
②將生成的4個檔案放在C盤的.ssh資料夾下,並應只包含這四個檔案。
3.新增私匙
①開啟ssh-agent:
ssh-agent bash
ssh-agent -s
如右圖: ②新增私匙:
4.配置config檔案
①在.ssh檔案中手動建立名為config的檔案,並按自己的資訊修改模板、填入檔案。
模板如下:
# 註釋1
Host 第一個Github賬號的倉庫名
HostName github.com
PreferredAuthentications publickey
IdentityFile 1私匙所在檔案路徑\1私匙名
User git
# 註釋2
Host 第二個Github賬號的倉庫名
HostName github.com
PreferredAuthentications publickey
IdentityFile 2私匙所在檔案路徑\2私匙名
User git
以下是我的檔案內容:
5.New ssh key
將兩個Github賬號的公匙分別新增到其Github賬號----Settings----SSH and GPG keys中。
https://blog.csdn.net/qq_41979043/article/details/83046278此部落格的----3----⑤中有具體過程。
6.遠端測試
ssh -T 倉庫名
最後:鑰匙變亮,說明配置成功!!
注意:此時ssh [email protected]命令變為ssh [email protected]賬號名.github.com。
附加:將Github倉庫克隆到本地。
注意此時與只有一個密匙時的輸入不同。
原來輸入:
git clone [email protected]: Github賬號使用者名稱/倉庫名
如:git clone [email protected]: read1002/read1002.github.io
現在輸入:
git clone [email protected]: read1002/read1002.github.io
如:git clone [email protected]: read1002/read1002.github.io