赞
踩
存在如下情况:我们自己又个GitHub账号,用来做自己的一些代码练习,公司有个其他git的账号如:gitlab、gerrit等,用来工作。此时我们需要配置两个ssh key.
git config --global user.name "用户名"
git config --global user.email "邮箱"
在c盘->Users->用户名->.ssh文件夹下执行git bash here命令:
ssh-keygen -t rsa -C "yourmail@gmail.com"
生成第一个ssh key,比如取名为id_rsa_github
此时会在C:\Users\用户名.ssh下生成如下文件
再次输入上面的命令,生成第二个ssh key。注意邮箱名字需是对应的另外一个账号的邮箱名。执行后会新生成两个文件。
ssh-agent
ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_gerrit
执行成功:
如果遇到如下问题:
Could not open a connection to your authentication agent.
执行:
ps aux | grep ssh
再执行
kill -9 线程号
然后在.ssh目录下用git bash执行:
exec ssh-agent bash
eval ssh-agent -s
最后再次添加ssh key
ssh-add ./id_rsa_github
ssh-add ./id_rsa_gerrit
在.ssh文件夹下创建名为config的文件(无后缀名)
创建好后,在git bash下执行touch config命令。
touch config
在config文件中输入如下内容:
# gerrit
Host gitool.glanway.com
HostName gitool.glanway.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gerrit
User userName
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
User userName
文件说明:
Host:是HostName的别名,可以自己取,一般取跟HostName一样的名字。
如果遮掩定义:Host mygithub,则在git clone时应如下输入:
git clone git@mygithub:PopFisher/AndroidRotateAnim.git
HostName:配置真正的域名
PreferredAuthentications:配置登录时用什么权限认证,如:publickey,password publickey,keyboard-interactive等
User:用户名
将对应的公钥添加到对应的github和gitlab上:
输入:
ssh -T git@github.com #测试github
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。