git多帳戶ssh配置

參考文獻
1.ssh-keygen 中文手冊-金步國
2.Windows下Git多帳號配置,同一電腦多個ssh-key的管理-popfisher
3.hexo同時託管到coding.net與githubhtml

1.生成公鑰

ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f 'id_rsa_coding'

其中:
ssh-keygen - 生成、管理和轉換認證密鑰
-t type 指定要建立的密鑰類型。可使用:"rsa1"(SSH-1) "rsa"(SSH-2) "dsa"(SSH-2)
-b bits 指定密鑰長度
-C comment 提供一個註釋
-f filename 指定密鑰文件名git

2.將公鑰新增到coding.net

帳戶-ssh公鑰處新增生成的私鑰對應的公鑰id_rsa_coding.pubgithub

3.新建config

coding.net多帳戶configsegmentfault

~/.ssh文件夾下新建config文件,寫入下列內容bash

Host github.com
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa
        User chrisji0518@outlook.com

Host git.coding.net
        User chrisji0518@outlook.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_coding

其中:
Host 別名
HostName 主機名
User 用戶名
IdentityFile 密鑰文件路徑hexo

4.測試

分別測試github和coding.net是否能夠鏈接ssh

ssh -T git@github.com
ssh -T git@git.coding.net

5.同時push

利用git remote add分別命名,在分別push測試

git remote add github 倉庫地址
git remote add coding 倉庫地址
...
git push github master
git push coding master
相關文章
相關標籤/搜索