断断续续使用Git一段时间,一直都是基于全局下配置Git帐号的。还没有配置过多个git帐号。今天正好需要使用两个远程地址。百度一下。顺便做一个记录。
一、使用ssh-keygen命令生成一组新的id_rsa_new和id_rsa_new.pub
$ssh-keygen -t rsa -C "newemail"
默认状态下都是 回车键,之后生成id_rsa和id_rsa.pub。如果想生成新的密码,需要如下图操作
之后~/.ssh/目录下会生成 id_rsa_new 和 id_rsa_new.pub 文件。拷贝id_rsa_new.pub里面的公钥放到SSH Keys中。
二、新建~/.ssh/config
如果config文件不存在,则新建这个文件。以下是我的机器配置:
#A Git@A Host agit HostName IP Address #域名也可 User mofei IdentityFile ~/.ssh/id_rsa //默认key #B Git@B Host bgit HostName IP Address #域名也可 User mofei IdentityFile ~/.ssh/id_rsa_new //新建key
Host就是每个SSH连接的单独代号,IdentityFile告诉SSH连接去读取哪个私钥。
三、识别新的私钥
$ssh-add ~/.ssh/id_rsa_new
在clone的时候需要使用host替换git@remoteaddress中的remoteaddress部分。如果之前配置了全局设置,需要删除,重新配置
//取消操作如下 $git config --global --unset user.name //取消全局设置 $git config --global --unset user.email //取消全局设置 //当前项目下添加新的git配置 $git config user.name "newname" $git config user.email "newemail"
四、实例
$cd /Users/mofei/wwwroot/home_user1 $git clone git@agit:xxx.git //注意此刻地址变化 $cd /Users/mofei/wwwroot/home_user2 $git clone git@bgit:xxx.git</span>
以上操作就可以实现同一客户端配置多个Git帐号。
刚好使用
[发红包]
又出现死命洗地的毛粉了。千错万错,反正不是管理者的错。