Linux操作拾遗——为git添加多个账户

如果你有多个git账户 比如一个github、一个开源中国、一个coding账号,想用ssh方式方便的git管理代码,如何实现呢,其实也比较简单

1.先使用ssh-keygen生成各自的公钥和私钥 比如开源中国的osc

ssh-keygen -t rsa -C "xxxxx@163.com" -f ~/.ssh/osc_id-rsa

继续生成coding.net的密钥对

ssh-keygen -t rsa -C "lhx880619@163.com" -f ~/.ssh/coding_id-rsa

完成后再~/.ssh目录中新建一个config文件

touch ~/.ssh/config

使用任意编辑器编辑内容如下:

# osc
Host git.oschina.net
    HostName git.oschina.net
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/osc_id-rsa
# coding
Host git.coding.net
    HostName git.coding.net
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/coding_id-rsa

目录中最终是这样滴

然后去各自平台添加ssh的公钥pub


本文由 Leo's Blog 创作,采用 署名-非商业性使用 2.5 中国大陆 进行许可。
如需转载、引用请署名作者且注明文章出处。
2017年07月11日 3621 浏览 评论 Linux
上一篇:Mysql 建表错误1071 - Specified key was too long; max key length is 767 bytes | 下一篇:Linux操作拾遗——为用户添加Home目录