https://coderwall.com/p/7smjkq/multiple-ssh-keys-for-different-accounts-on-github-or-gitlab
Multiple SSH keys for different accounts on Github or Gitlab
SSH GIT GITLAB GITHUB
Sometimes you need more accounts than one for access to Github or Gitlab and similar tools. For example you can have one account for your projects at home and second account for your company.
Case 1: Multiple accounts on Github
Create SSH keys with different names
$ ssh-keygen -t rsa -C "your_name@home_email.com"
When you see this message
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user_name/.ssh/id_rsa):
Enter unique name, for example:
id_rsa_home
Next, you'll be asked to enter a passphrase.
So, you'll have created SSH key for your home account, now you can generate SSH key for your company account.
Call SSH key generator again with second mail.
$ ssh-keygen -t rsa -C "your_name@company_email.com"
Enter name for file
id_rsa_company
After all steps you can check that all keys were created.
$ ls ~/.ssh
You should see a similar files list:
id_rsa_home id_rsa_company id_rsa_home.pub id_rsa_company.pub
Now you need a config file for organise these keys.
$ cd ~/.ssh/
$ touch config
$ nano config
Add into config file:
Home account
Host home.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_home
Company account
Host company.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
Next you'll delete cached keys
$ ssh-add -D
If you see a message
Could not open a connection to your authentication agent.
Then enter:
eval ssh-agent -s
and try again previous command.
Next, you can check that your keys were added:
$ ssh-add -l
2048 d4:e0:39:e1:bf:6f:e3:26:14:6b:26:73:4e:b4:53:83 /home/user/.ssh/id_rsa_home (RSA)
2048 7a:32:06:3f:3d:6c:f4:a1:d4:65:13:64:a4:ed:1d:63 /home/mateusz/.ssh/id_rsa_company (RSA)
If you haven't any entries then you should add your keys
ssh-add ~/.ssh/id_rsa_company
ssh-add ~/.ssh/id_rsa_home
Now you can check connection
$ ssh -T git@home.github.com
Hi home_user! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@work.github.com
Hi company_user! You've successfully authenticated, but GitHub does not provide shell access.
Note! Check the last paragraph of this tip.
Case 2: Account on Github and Gitlab
This is very similar case to the previous. I won't describe it step by step, because all steps are the same. I'll add only example config file.
For example you have own account for home works and company account on gitlab.
GITLAB
Host gitlab.company_url.com
HostName gitlab.company_url.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
GITHUB
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_home
The test connections
$ ssh -T git@gitlab.company_url.com
Welcome to GitLab, CompanyUser!
$ ssh -T git@github.com
Hi home_user! You've successfully authenticated, but GitHub does not provide shell access.
As you probably have seen, prefix on hostname isn't required.
You may need to set git config user details for any project.
It's required to distinguish your accounts.
$ cd ~/home_project
$ git config user.name "home_user"
$ git config user.email "your_name@home_email.com"
https://coderwall.com/p/7smjkq/multiple-ssh-keys-for-different-accounts-on-github-or-gitlab的更多相关文章
- Multiple SSH keys for different accounts on Github or Gitlab
[inside this square brackets give a name to the followed acc.] name = github_username email = github ...
- git SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab. Before gene ...
- Generating SSH Keys [Ubuntu Linux]
Generating SSH Keys We strongly recommend using an SSH connection when interacting with GitHub. SSH ...
- ssh keys管理工具
原文地址:https://rtyan.github.io/%E5%B7%A5%E5%85%B7/2017/09/12/ssh-keys-manager.html 引言 我有两个github账户,一个是 ...
- Git多个SSH KEYS解决方案(含windows自动化、TortoiseGit、SourceTree等)
工作过程中,经常会使用到多个git仓库,每个git仓库对应一个账号,可以理解为每个git仓库对应一个ssh key,因此我们需要管理多个ssh key. 一.快速创建ssh key 1. 创建 ...
- How To Set Up SSH Keys
How To Set Up SSH Keys.https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
- 为github帐号添加SSH keys(Linux和Windows)
文章转自:https://blog.cofface.com/archives/406.html/2 一.Linux增加ssh keys方法: 使用git clone命令从github上同步github ...
- 为Github 托管项目的访问添加SSH keys
为了便于访问远程仓库,各个协作者将自己的本地的项目内容推送到远程仓库中,使用 SSH keys 验证github的好处:不用每次提交代码时都输入用户名和密码. 如果SSH key没有添加到github ...
- 七、配置ssh keys连通github跟ssh-agent
jenkins+github配置完成后,能够实现在提交pull request或者直接push时,能够将提交的代码拉去一份到服务器本地,并自动merge:但是代码拉去下来了,部署环境的时候却需要输入登 ...
随机推荐
- es6-Symbol用法
1.symbol概念 这种数据类型提供独一无二值 比如,在JS中,我可以通过数据类型生成变量a=number05,也可以生成b=nubmer05,这两个变量可以说是相等的. 但是用symbol生成的值 ...
- S-HR快速查看shr日志
http://localhost:6888/shr/appData.do?method=getApplicationLog&logFile=apusic.log.0&instance= ...
- switch 语句的反汇编浅析
switch 的简单情景(case 不超过 3 项) 首先,我们分析一下 switch 语句的一种简单情景,我们可以用 C 写出如下如下代码. 编译后用 OllyDBG 载入,它将显示出如下的反汇编代 ...
- 51nod1117 聪明的木匠【贪心+优先队列】
一位老木匠需要将一根长的木棒切成N段.每段的长度分别为L1,L2,......,LN(1 <= L1,L2,-,LN <= 1000,且均为整数)个长度单位.我们认为切割时仅在整数点处切且 ...
- safari浏览器click事件要点击两次才有响应出现闪烁
闪烁问题 由于在iOS Safari上click事件存在300ms响应延时,所以为touch事件添加样式,会和click事件默认样式叠加而产生闪烁问题. 因为ios safari浏览器中对触摸事件的响 ...
- SIM卡中UCS2编码的三种格式(80,81,82)分析
网上看到一篇比较好的说ucs2编码的文章,保存一下,原文地址: http://hi.baidu.com/youren4548/blog/item/fa08bd1bf61005058618bf1d.ht ...
- 奇妙的go语言(基本的语法)
[ 声明:版权全部,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 学习一门新的语言无非就是从主要的语法開始的.通过语法书来学习语言毕竟是很枯燥的,所以我们最好还 ...
- C++管理指针成员
1.C++中一般採用以下三种方法之中的一个管理指针成员: (1)指针成员採取常规行为. 这种类具有指针的全部缺陷:具有指针成员且使用默认复制构造函数和赋值操作符,无法避免悬垂指针(两个对象的指针成员指 ...
- Android解决使用findViewById时须要对返回值进行类型转换问题的辅助类
在我们的开发工作时,findViewById可能是用得最多的函数之中的一个.但它特别讨厌的地方就是我们常常须要对返回的view进行类型转换,输入麻烦.代码丑陋,比如曾经我们在Activity中找一些子 ...
- 在Mac OS X中部署Tomcat的经验
因为前几天重装了Mac的系统.准备接下来把一些必需的实验环境都搭建起来.这里简单总结一下在Mac OS X上部署Tomcat应该注意的事情: 下载Tomcat的相应版本号,如http://tomcat ...