原文連接:GitHub 多帳戶設置git
個人兩個 GitHub 帳戶分別爲主帳戶(參與開源項目和本身的代碼)和副帳戶(更新 Hexo 博客)。github
本文會介紹在擁有多個 GitHub 帳號的時候,如何經過配置 SSH 文件來讓各個帳戶正常工做且不發生衝突。shell
因爲不一樣的 GitHub 不能使用同一個 SSH 公鑰,因此要生成兩個不一樣的 SSH 分別對應兩個主帳戶和副帳戶。ssh
Ubuntu 生成 SSH 的命令以下:post
ssh-keygen -t rsa -f ~/.ssh/id_rsa_blog -C "blogemail@gmail.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "mainemail@gmail.com"
複製代碼
-f
選項指定生成鑰匙對的文件名。測試
正確操做後目錄 .ssh/
下應該是這樣的:spa
編輯 ~/.ssh/config
SSH 配置文件,沒有該文件則新建。code
# mainemail@gmail.com
Host github-main.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# blogemail@gmail.com
Host github-blog.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_blog
複製代碼
而後,之後使用 main 帳戶添加遠程倉庫須要這樣添加:orm
git remote add origin git@github-main.com:username/demo.git
複製代碼
相似,使用 blog 帳戶時是這樣:cdn
git remote add origin git@github-blog.com:username/demo.git
複製代碼
而非原來的:
git remote add origin git@github.com:username/demo.git
複製代碼
部署相應的 SSH 公鑰到 GitHub 後,嘗試在相應的本地倉庫 git push
幾個文件測試。