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_emailaddress
[any other name]
name = github_username
email = github_email
[credential]
helper = osxkeychain
useHttpPath = true
Multiple SSH keys for different accounts on Github or Gitlab
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"
Multiple SSH keys for different accounts on Github or Gitlab的更多相关文章
- mac下生成ssh keys 并上传github仓储
使用github仓储需要本机生成一个公钥key 添加到自己的git账户SSH keys中 mac 生成方法: 1. 打开终端 输入 ssh-keygen 然后系统提示输入文件保存位置等信息 ...
- git的id_rsa.pub的生成(也就是github上的SSH Keys)
只需要一条语句就可以实现生成id_rsa.pub和id_rsa的目的:ssh-keygen -t rsa -C your_email 注意:这个邮箱是你github上的邮箱.只有在gthub上添加了这 ...
- 为github帐号添加SSH keys
为github帐号添加SSH keys 2012-05-26 00:05 34279人阅读 评论(6) 收藏 举报 ssh文本编辑gitvim工具up 使用git clone命令从github上同步g ...
- GitHub 添加 SSH keys
首先在本地创建 SSH Keys $ ssh-keygen -t rsa -C "18817801185@163.com" 后面的邮箱即为 github 注册邮箱,之后会要求确认路 ...
- 为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:但是代码拉去下来了,部署环境的时候却需要输入登 ...
- Generating SSH Keys for github
由于最近电脑重装了Windows 8.1, 想用github维护一些代码.故不得不重新生成一下ssh key. 按https://help.github.com/articles/generating ...
- 添加SSH keys到github帐号
使用git clone命令从github上同步github上的代码库时,如果使用SSH链接(如我自己的esesgrid项目:git@github.com:hmilycc/esesgrid.git),而 ...
随机推荐
- struts2:OGNL表达式,遍历List、Map集合;投影的使用
OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通过它简单一致的表达式语法,可以存 ...
- 【Android】Android开源项目精选(一)
ListView ListView下拉刷新:https://github.com/johannilsson/android-pulltorefresh AndroidPullToRefresh:htt ...
- Spring Boot 应用 发布到Docker
Spring Boot 应用 先把命令行切换到Maven项目的根目录 E:\gitCode\galaxyguardians 通过mvn clean package命令打包应用程序 ,在E:\gitCo ...
- 《软件测试自动化之道》读书笔记 之 XML测试
<软件测试自动化之道>读书笔记 之 XML测试 2014-10-07 待测程序测试程序 通过XmlTextReader解析XML 通过XmlDocument解析XML 通过XmlPa ...
- 20款最好的jQuery文件上传插件
当它是关于开发网络应用程序和网页的时候,文件上传功能的重要性是不容忽视的.一个文件上传功能可以让你上传所有类型的文件在网站上,包括视频,图像,文件和更多.创建一个文件上传功能,对你的网站是不是很难,有 ...
- iOS开发 关于启动页和停留时间的设置
引言: 在开发一款商业App时,我们大都会为我们的App设置一个启动页. 苹果官方对于iOS启动页的设计说明: 为了增强应用程序启动时的用户体验,您应该提供一个启动图像.启动图像与应用程序的首屏幕看起 ...
- 【GMT43智能液晶模块】例程七:定时器PWM实验——简易电子琴
实验原理: STM32定时器有PWM功能,GMT43模块上带有一无源蜂鸣器,其 PWM输入控制信号接在STM32定时器输出接口上(PB4/TIM3_CH1),可 以通过定时器的PWM输出频率从而控制蜂 ...
- WebRTC 零基础开发者教程(中文版)下载
WebRTC 简介 WebRTC,是一个支持网页浏览器进行实时语音通话或视频聊天的技术,是谷歌2010年以6820万美元收购Global IP Solutions公司而获得的一项技术. WebRTC提 ...
- Java知多少(31)static关键字以及Java静态变量和静态方法
static 修饰符能够与变量.方法一起使用,表示是“静态”的. 静态变量和静态方法能够通过类名来访问,不需要创建一个类的对象来访问该类的静态成员,所以static修饰的成员又称作类变量和类方法.静态 ...
- Java知多少(54)断言详解
断言的概念 断言用于证明和测试程序的假设,比如“这里的值大于 5”.断言可以在运行时从代码中完全删除,所以对代码的运行速度没有影响. 断言的使用 断言有两种方法: 一种是 assert<< ...