博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS7上GitHub/GitLab多帐号管理SSH Key
阅读量:6903 次
发布时间:2019-06-27

本文共 1368 字,大约阅读时间需要 4 分钟。

由于公司团队使用 GitLab 来托管代码,同时,个人在 Github 上还有一些代码仓库,可公司邮箱与个人邮箱是不同的,由此产生的 SSH key 也是不同的,这就造成了冲突 ,文章提供此类问题的解决方案:如何在一台机器上面同时使用 Github 与 Gitlab 的服务?

生成GitHub/GitLab 的 SSH Key

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "123456@qq.com"$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitlab -C "admin@example.com"

检查key是否生成,执行下面的命令,有id_rsa_githubid_rsa_gitlab以及他们的公钥文件就是成功了。

$ ls ~/.ssh

1549915-20190424152503776-1646719427.png

添加private key

$ ssh-add ~/.ssh/id_rsa_github$ ssh-add ~/.ssh/id_rsa_gitlab

如果执行ssh-add时提示"Could not open a connection to your authentication agent",可以先执行命令:

$ ssh-agent bash,然后再运行ssh-add命令。

# 可以通过 ssh-add -l 来确私钥列表$ ssh-add -l # 可以通过 ssh-add -D 来清空私钥列表$ ssh-add -D

修改配置文件

$ vi ~/.ssh/config

# githubHost github.com    HostName github.com    PreferredAuthentications publickey    IdentityFile ~/.ssh/id_rsa_github # gitlabHost gitlab.example.com    HostName gitlab.example.com    PreferredAuthentications publickey    IdentityFile ~/.ssh/id_rsa_gitlab

上传public key 到 GitHub/GitLab

GitHub设置过程如下

登录github,点击右上方的图标,点击“Settings”

1549915-20190424152932010-1088974810.png

选择“SSH and GPG keys”,点击“New SSH key”,在出现的界面中填写SSH key的名称,填一个你自己喜欢的名称即可,然后将上面拷贝的 ~/.ssh/id_isa_github.pub 文件内容粘帖到 key 一栏,在点击“Add SSH key”按钮就可以了。

GitLab设置过程如下:

点击“Profile Settings”

1549915-20190424153044068-1734292385.png

点击“SSH Keys”,添加SSH key

1549915-20190424153116770-1266737236.png

测试

添加过程github会提示你输入一次你的github密码 ,确认后即添加完毕。

# 测试github$ ssh -T git@github.com # 测试gitlab$ ssh -T git@gitlab.example.com

转载于:https://www.cnblogs.com/mingyue5826/p/10762673.html

你可能感兴趣的文章
电话号码分身
查看>>
Redis持久化方案
查看>>
Unity保存序列化数据
查看>>
测试jupyter notebook导出md格式的兼容性
查看>>
【转】WPF MultiBinding 和 IMultiValueConverter
查看>>
解决springMVC文件上传报错: The current request is not a multipart request
查看>>
Struts2国际化-getText()方法
查看>>
实时监听组件中路由的变化
查看>>
MnasNet:迈向移动端机器学习模型设计的自动化之路
查看>>
选项卡的JS
查看>>
青蛙的约会(扩展欧几里得)
查看>>
Asia Yokohama Regional Contest 2018 C题 - Arithmetic Progressions(思维)
查看>>
UVa 101 - The Blocks Problem STL
查看>>
计算机专业术语
查看>>
Leetcode-探索 | 移动零
查看>>
DBI 数据库模块剖析:Perl DBI 数据库通讯模块规范,工作原理和实例
查看>>
Tesseract+opencv+VS+win实现OCR
查看>>
android在activity中锁屏解锁后重走OnCreate的问题的解决办法
查看>>
[学习笔记]博弈论
查看>>
python基础:搜索路径
查看>>