CentOS7上GitHub/GitLab多帐号管理SSH Key
由于公司团队使用 GitLab 来托管代码,同时,个人在 Github 上还有一些代码仓库,可公司邮箱与个人邮箱是不同的,由此产生的 SSH key 也是不同的,这就造成了冲突 ,文章提供此类问题的解决方案:如何在一台机器上面同时使用 Github 与 Gitlab 的服务?
由于公司不允许访问外网22端口,所以我们可以改走443端口
Using SSH over the HTTPS port
https://help.github.com/articles/using-ssh-over-the-https-port/
测试https端口连通性
# ssh -T -p git@ssh.github.com
修改ssh配置文件
# vi ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port
然后通过以下方式测试
# ssh -T git@github.com
1. 生成GitHub/GitLab 的 SSH Key
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "285006386@qq.com"
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitlab -C "admin@example.com"
检查key是否生成
$ ls ~/.ssh
2. 添加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
3. 修改配置文件
$ vi ~/.ssh/config
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github # gitlab
Host gitlab.example.com
HostName gitlab.example.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
4. 上传public key 到 GitHub/GitLab
GitHub设置过程如下:
登录github,点击右上方的图标,点击“Settings”

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

添加过程github会提示你输入一次你的github密码 ,确认后即添加完毕。
GitLab设置过程如下:
点击“Profile Settings”

点击“SSH Keys”,添加SSH key

5. 测试
# 测试github
$ ssh -T git@github.com # 测试gitlab
$ ssh -T git@gitlab.example.com
CentOS7上GitHub/GitLab多帐号管理SSH Key的更多相关文章
- 多github帐号的SSH key切换
我有两个github帐号,一个是个人所用,一个是为公司项目所用.如果是单用户(single-user),很方便,默认拿id_rsa与你的github服务器的公钥对比:如果是多用户(multi-user ...
- 多个github帐号的SSH key切换
写在前面的话 github账号,工作有一个,自己有一个.但是默认下使用ssh key在git push时只有默认账号能免输入账号和密码. 如果想让另一个账号在代码push时免账号和密码,请看这篇文章h ...
- 【Git笔记】怎样在同主机同账户下实现多个gitlab帐号管理各自的remote repo
我们可能会遇到以下的场景: 1)多人共用同一台Linux开发机,该开发机仅仅有一个共用的work帐号,非常多人都用这个帐号登录主机进行日常开发. 2)该work帐号下统一安装了gitclient供多人 ...
- GitHub学习心得之 安装配置与多帐号管理
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 GitHub学习心得之 安装配置与多帐号管理 1.前言2.GitHub Linux安装(ub ...
- Linux入门进阶第五天——用户管理(帐号管理 )上
一.帐号与群组 关于使用者帐号: 用户的ID与帐号信息所在位置是 /etc/passwd,而管理密码的数据则是在 /etc/shadow 每个登陆的使用者至少都会取得两个 ID , 一个是使用者 ID ...
- 在GitHub多个帐号上添加SSH公钥
GitHub后台可以添加多个SSH Keys,但是同一个SSH Keys只能在添加在一个帐号上(添加时提示“Key is already in use”).理由很容易想到,SSH公钥使用时相当于用户名 ...
- 为GitLab帐号添加SSH keys并连接GitLab
https://blog.csdn.net/xyzchenxiaolin/article/details/51852333 为github帐号添加SSH keys使用git clone命令从GitLa ...
- 为github帐号添加SSH keys
为github帐号添加SSH keys 2012-05-26 00:05 34279人阅读 评论(6) 收藏 举报 ssh文本编辑gitvim工具up 使用git clone命令从github上同步g ...
- 鸟哥的linux私房菜——第十三章学习(Linux 帐号管理与 ACLL 权限设置)
第十三章.Linux 帐号管理与 ACLL 权限设置 1.0).使用者识别码: UID 与 GID UID :User ID GID :group ID [root@study ~]# ll -d / ...
随机推荐
- XXX is not in the sudoers file.This incident will be reported
在fefora 10安装xz解压软件时,sudo make install 时,报错: 原因未知,在网上搜索为:权限问题,解决办法如下(来自百度): 解决方法如下: >.进入超级用户模式.也就是 ...
- WordPress Woopra plugin remote PHP arbitrary code execution exploit.
测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! # Exploit Title: woopra plugins execute arbitrary PHP code E ...
- (转载)Linux中cp直接覆盖不提示的方法
(转载)http://soft.chinabyte.com/os/220/11760720.shtml 新做了服务器,cp覆盖时,无论加什么参数-f之类的还是提示是否覆盖,这在大量cp覆盖操作的时候是 ...
- SQL SERVER 的 INFORMATION_SCHEMA 的使用
------------------------------------------------------- 第一个查询看看库里有多少个表,表名等 select * from INFORMATION ...
- HDOJ/HDU 1242 Rescue(经典BFS深搜-优先队列)
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is ...
- Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- (转载)TRS的WCM6漏洞权限绕过以及绕过密码的登陆方式
转载于:http://www.2cto.com/Article/201302/191261.html 1.由来:建立在 TRS的WCM6可直接获取管理员密码 漏洞的基础上 2.首先访问wcm目录, ...
- linux下在多个文件夹中查找指定字符串的命令
例如,想要在当前文件夹下的多个.c或者.txt文件中查找“shutdown”字符串, 可以使用“grep shutdown ./*.c”或“grep shutdown ./*.txt”即可 使用fin ...
- windows ntp安装及调试
Setting up NTP on Windows It's very helpful that Meinberg have provided an installer for the highly- ...
- JVM performance profiling (有待整理)
Agenda memory model 3 parts: heap, permgen (method area) , thread stack(pointer, local var) heap: yo ...