Linux操作拾遗——为git添加多个账户
如果你有多个git账户 比如一个github、一个开源中国、一个coding账号,想用ssh方式方便的git管理代码,如何实现呢,其实也比较简单
1.先使用ssh-keygen生成各自的公钥和私钥 比如开源中国的oscssh-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 中国大陆 进行许可。
如需转载、引用请署名作者且注明文章出处。