多个git账号的SSH配置

一般使用git都只需要维持一个默认的git账户就可以打天下了。

但如果自己确实需要多个git账号的需求的话,就有必要配置多个ssh key了。

首先为生成多个ssh key

ssh-keygen -t rsa -C "mygit@myemail.com"

 在shell中的交互中输入保存的文件名比如id_rsa_github,以及私钥密语(随意)

 

比如你可以为github, bitbucket和自己公司都生成一个对应的ssh key

 

默认情况下~/.ssh目录下没有config文件,需要自己手动加一个

cd ~/.ssh
touch config

 

配置一下config文件,添加规则

Host github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

Host bitbucket.org
HostName  bitbucket.org
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_bucket

Host git.company.com
HostName git.company.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company

 

这样的话,就可以在不同的git服务器上使用不同的ssh认证了

 

 

参考链接:

http://stackoverflow.com/questions/3225862/multiple-github-accounts-ssh-config

http://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574

posted @ 2016-07-11 01:24  活在夢裡  阅读(754)  评论(0编辑  收藏  举报