GIT SSH多账户配置
2016-06-09 00:00
288 查看
摘要: 在我们日常的开发工作中,会用到多个GIT仓库(公司内部的GIT仓库、github、oschina的git仓库等),这就需要我们配置不同的ssh-key
ref:
https://gist.github.com/suziewong/4378434
http://www.liaohuqiu.net/cn/posts/using-diffrent-user-config-for-different-repository/
http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/
http://www.blogjava.net/lishunli/archive/2012/03/08/371556.html
https://segmentfault.com/a/1190000002994742
1、生成多对公私钥对应多个git服务器并将公钥copy到服务器上
ssh-keygen -t rsa -C "chenyh@yunhetong.net" -f id_rsa_work ssh-keygen -t rsa -C "hzchenyh@163.com" -f id_rsa_osc
2、配置全局config
全局配置文件在~/.ssh/下的config文件中:# oschina(hzcheyh@163.com) ======================================== Host osc HostName git.oschina.net User hzchenyh@163.com IdentityFile ~/.ssh/id_rsa_osc # yunhetong(chenyh@yunhetong.net) ======================================== Host yunhetong HostName 120.20.72.179 Port 7999 User git IdentityFile ~/.ssh/id_rsa_work
3、ssh测试连通性
#测试ssh到osc的连通性(osc即为上面配置的host别名) ssh -T git@osc
4、取消git全局name和email配置,并为每个项目设置独立的name和email
#取消git全局config git config --global --unset user.name git config --global --unset user.email #(公司项目)进入项目目录下,为每个项目设置name和email git config user.name 醉公子 git config user.email chenyh@yunhetong.net #(自己项目)进入项目目录下,为每个项目设置name和email git config user.name 醉公子osc git config user.email hzchenyh@163.com
5、修改每个项目中.git目录下的config文件的配置
[core] ...... [remote "origin"] #url = ssh://git@120.20.72.179:7999/chenyh/user.git 此为原始URL,经上面的host替换后如下所示 url = ssh://git@yunhetong/chenyh/user.git fetch = +refs/heads/*:refs/remotes/origin/* [user] name = 醉公子 email = chenyh@yunhetong.net
[core] ...... [remote "origin"] #url = git@git.oschina.net:hzchenyh/jfinal.git url = git@osc:hzchenyh/jfinalBlog.git fetch = +refs/heads/*:refs/remotes/origin/* # 以下表示本地默认分支master和远程分支master的一个对应关系 [branch "master"] remote = origin merge = refs/heads/master [user] name = 醉公子osc email = hzchenyh@163.com
ref:
https://gist.github.com/suziewong/4378434
http://www.liaohuqiu.net/cn/posts/using-diffrent-user-config-for-different-repository/
http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/
http://www.blogjava.net/lishunli/archive/2012/03/08/371556.html
https://segmentfault.com/a/1190000002994742
相关文章推荐
- RPC failed; result=22, HTTP code = 411
- Linux Generating SSH Keys
- git更新已經刪除的文件
- 提取Git每次提交后Commit的文件
- GIT迁移服务器
- 分布式版本管理git入门指南使用资料汇总及文章推荐
- git终极指南:在实际开发中的应用
- perl脚本实现限制ssh最大登录次数(支持白名单)
- rsync ssh 数据同步分析
- 搭建SSH时的思考和遇到的几个问题的解决方法
- SSH框架网上商城项目第9战之添加和更新商品类别功能实现
- SSH框架网上商城项目第7战之整合Struts2和Json
- SSH 使用原理 与解释
- SSH整合中 hibernate托管给Spring得到SessionFactory
- Linux VPS利用SSH重置ROOT密码的方法
- SSH框架网上商城项目第15战之线程、定时器同步首页数据
- SSH框架网上商城项目第18战之过滤器实现购物登录功能的判断
- ssh,scp自动登陆的实现方法
- Git远程操作详解