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
相关文章
相关标签/搜索