git多账户ssh配置

参考文献
1.ssh-keygen 中文手册-金步国
2.Windows下Git多账号配置,同一电脑多个ssh-key的管理-popfisher
3.hexo同时托管到coding.net与github

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 指定密钥文件名

2.将公钥新增到coding.net

账户-ssh公钥处新增生成的私钥对应的公钥id_rsa_coding.pub

3.新建config

coding.net多账户config

~/.ssh文件夹下新建config文件,写入下列内容

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 密钥文件路径

4.测试

分别测试github和coding.net是否可以连接

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
posted @ 2017-11-12 22:19  guidetheorient  阅读(246)  评论(0)    收藏  举报