一台机器上多账户管理——SSH Key切换解决push冲突
来源:互联网 发布:雷姆雷姆软件汉化版 编辑:程序博客网 时间:2024/06/05 09:21
1 同一个邮箱
由于邮箱是识别的唯一手段,那么自然的,这两者采用同一个邮箱,生成的 public key 也会是同一个,上传到 Github 或者 Gitlab 上面,在 Git 的配置中 ,设置好 Global 的配置 :
git config --global user.name 'ZhangXinNan'git config --global user.email 'zhangxin19870504@163.com' git config --global core.editor vim
进行日常的开发是没有问题的。
一个邮箱使用github参考github使用入门,写得比简单,如果有细节 不明白可以留言,我会补充或者 回答 。
实际生活中采用同一个邮箱的可能性并不是太大,这就引出了方案二.
2 不同邮箱
2.1 生成ssh-key
生成默认,Github使用
ssh-keygen -t rsa -b 4096 -C "zhangxin19870504@163.com"
此命令创建了~/.ssh文件夹,同时生成了
id_rsa id_rsa.pub
生成公钥、密钥的同时指定文件名,Gitlab使用
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "zhangxin0627@autohome.com.cn"
上传public key 到github或者gitlab
以Github为例,过程如下:
登录github点击右上方的Accounting settings图标选择 SSH key点击 Add SSH key在出现的界面中填写SSH key的名称,填一个你自己喜欢的名称即可,然后将上面拷贝的~/.ssh/id_rsa.pub文件内容粘帖到key一栏,在点击“add key”按钮就可以了。添加过程github会提示你输入一次你的github密码 ,确认后即添加完毕。 上传Gitlab的过程一样,请自己操作。
2.2 配置config文件
在 ~/.ssh目录下,如果不存在,则新建 touch ~/.ssh/config文件 ,文件内容添加如下:
# Default github user(first@mail.com),注意User项直接填git,不用填在github的用户名Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa# second user(second@mail.com)# 建一个gitlab别名,新建的帐号使用这个别名做克隆和更新Host git.corpautohome.com HostName git.corpautohome.com User zhangxin0627 IdentityFile ~/.ssh/id_rsa.gitlab
配置完成后,符合 *.corp.xxx.com后缀的 Git 仓库,均采取~/.ssh/id_rsa.gitlab 密钥进行验证,其它的采取默认的。
2.3 难证是否OK
由于每个托管商的仓库都有唯一的后缀,比如 Github的是 git@github.com:*,所以可以这样测试:
➜ ~ ssh -T git@github.comThe authenticity of host 'github.com (192.30.255.112)' can't be established.RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.Hi ZhangXinNan! You've successfully authenticated, but GitHub does not provide shell access.➜ ~ ssh -T git@git.corpautohome.comThe authenticity of host 'git.corpautohome.com (10.168.100.80)' can't be established.RSA key fingerprint is SHA256:SufpdWzsO0cdXqgj0/h141fs+7RjQamTq8so25Y60WI.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'git.corpautohome.com,10.168.100.80' (RSA) to the list of known hosts.Welcome to GitLab, zhangxin0627!
看到这些 Welcome 信息,说明就是 OK的了。
配置
2.4 全局配置,Github仓库中默认使用此配置
git config --global user.name 'ZhangXinNan'git config --global user.email 'zhangxin19870504@163.com'
2.5 团队项目配置,每次新创建一个项目,需要执行下
git config --local user.name 'ZhangXinNan'git config --local user.email 'zhangxin0627@autohome.com.cn'
3 参考资料:
一台机器上Github/Gitlab多账户管理SSH Key切换解决push冲突
阅读全文
0 0
- 一台机器上多账户管理——SSH Key切换解决push冲突
- git 在一台机器上配置多个账户
- 一台电脑如何管理多个SSH KEY
- 一台机器运行多个JBoss多实例, 解决JBoss端口冲突
- 一台机器安装多套hadoop环境 端口冲突的解决
- 同一台电脑关于多个SSH KEY管理
- 解决为多个git账户的id_rsa文件在一台共享server上共存工作的问题
- 一台机器上运行多台服务器
- Github多个SSH key切换管理项目
- Git配置 多账户SSH KEY
- ssh-key 与 git账户配置以及多账户配置
- 一台机器上启动两个tomcat端口号冲突问题
- 多 SSH Key 管理技巧与 Git 多账户登录问题
- 多个SSH key切换
- 一台机器配置多个Git账户
- 解决一台机器同时运行多个Tomcat服务
- 一台机器上多操作系统安装原理
- 在一台机器上运行多个PostgreSQL实例
- CentOS下RabbitMQ安装配置
- python day03 自定义功能化的购物车 装饰器的使用
- Oracle数据库误操作回滚到指定的时间点
- 菜鸟先飞之JAVA_内部类
- 百度-离线地图
- 一台机器上多账户管理——SSH Key切换解决push冲突
- cookie 中域的理解
- gulp学习指南
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- java String StringBuffer StringBudlider 区别
- MySQL 分区表以及操作
- 套接字、UDP通信、TCP通信、TCP\IP协议簇
- Django学习笔记二:实现博客详情,完善文章的分类和标签
- spring boot 不同的环境使用不同的配置