代码改变世界

git 创建多个账户ssh

2015-12-24 11:32  硕硕  阅读(514)  评论(0编辑  收藏  举报

创建一个账户

创建ssh本地秘钥。


$ ssh-keygen -t rsa -C "youremail@xxx.com"

一路回车,会在~/.ssh/目录下生成id_rsa和id_rsa.pub两个文件

用文本编辑器打开id_rsa.pub里的内容,在Github中添加SSH Keys

不明白的请参考GitHub创建SSH Keys

创建其他账户

创建第二个秘钥


$ ssh-keygen -t rsa -C "youremail2@xxx.com"

Enter file in which to save the key (......../id_rsa): my

// **切记** my这个地方请输入自定义名称,不然和第一个重复,将创建不成功或者覆盖,

一路回车,或者根据需要填入密码等等

找到新创建的文件,一般在上面的括号的路径里面.拷贝到.ssh文件夹里面

在.ssh/下创建config文件 内容如下:




Host github.com

  HostName github.com

  PreferredAuthentications publickey

  IdentityFile ~/.ssh/id_rsa

Host my.github.com

  HostName github.com

  PreferredAuthentications publickey

  IdentityFile ~/.ssh/my

打开my.pub拷贝内容,并添加到网站上面的SSH上面。


pbcopy < ~/.ssh/my.pub

测试配置是否正确


git -T git@github.com

git -T git@my.github.com

如果出现Hi xxx!You've successfully authenticated 就说明连接成功了