您的位置:首页 > 其它

管理Git生成多个ssh key

2016-08-23 17:41 176 查看

管理Git生成多个ssh key

生成两个key
生成key的命令
ssh-keygen -t rsa -C “Your Email Address” -f  'Your Name'
,-f后面给的生成key的名字,如果没有指定新的名字,那么每次ssh-keygen生成的名字相同,就会发生覆盖同名文件的情况的发生。

生成两个key后,添加到对应服务器的ssh kyes管理设置中。
本地添加私钥
本地添加私钥名命令
ssh-add ~/.ssh/Your Key Name
,如果出现“Could not open a connection to your authentication agent”的问题,可以执行命令
ssh-agent bash
,再运行添加命令。另外,可用通过
ssh-add -l
查看私钥列表
ssh-add -D
来清空私钥列表

修改配置文件
1.在~/.ssh目录下新建一个config的文件
2.添加以下内容
# oschina
Host git.oschina.net
HostName git.oschina.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/oschina
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
3.一点说明
以上的我采用的是oschina的码云和github的两种kye的结合体,其中每段最后的
IdentityFile
跟着是你自己ssh key的名字,不要搞错了。
最后就是测试咯
oschina的测试方法
ssh -T git@git.oschina.net
;成功收到的回复为“Welcome to Git@OSC,‘Your Name’ ”
github的测试方法
ssh -T git@github.com
;成功收到的回复为”Hi ’Your Name‘ ! You’ve successfully authenticated, but GitHub does not provide shell access.“

借鉴文章
git 配置多个SSH-Key
管理git生成的多个ssh key
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git ssh