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),而 ...
随机推荐
- iOS的动态代理模式的实现
动态代理模式的应用很多,特别是在不能修改被代理类的前提下,要对执行某些方法时需要打log或者捕捉异常等处理时,是一个非常方便的方法.只需要少量修改客户端(场景类)代码和添加一个代理类就可以实现,这个符 ...
- 4. Tensorflow的Estimator实践原理
1. Tensorflow高效流水线Pipeline 2. Tensorflow的数据处理中的Dataset和Iterator 3. Tensorflow生成TFRecord 4. Tensorflo ...
- post请求数据量过大,提交失败
HttpRuntimeSection.MaxRequestLength 属性,请求的最大大小(以千字节为单位). 默认大小为 4096 KB (4 MB) <system.web> < ...
- 深刻理解Python中的元类(metaclass)【转】
译注:这是一篇在Stack overflow上很热的帖子.提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解.他知道这肯定和自省有关,但仍然觉得 ...
- 教你一招:修复win7 系统自带的截图工具损坏
这个问题经常见,原因是注册表没有导入. 修复很简单. 打开资源管理器,在C盘中搜索到 tpcps.dll ,在其中选一个右击,选择注册dll,然后截图工具就被修复了. 有时候便签也会出现类似问题,方法 ...
- Java知多少(15)字符串
从表面上看,字符串就是双引号之间的数据,例如“微学苑”.“http://www.weixueyuan.net”等.在Java中,可以使用下面的方法定义字符串: String stringName ...
- Linux系统排查4——网络篇
用于排查Linux系统的网络故障. 网络排查一般是有一定的思路和顺序的,其实排查的思路就是根据具体的问题逐段排除故障可能发生的地方,最终确定问题. 所以首先要问一问,网络问题是什么,是不通,还是慢? ...
- python日志,一个改版SMTPHandler
1.官方logging包的SMTPHandler不支持ssl的邮箱,修改成兼容ssl以支持大部分国内邮箱. 2.增加一个频率控制的参数,比如要设置一个报警邮件,异常时候通知我们,但假设1分钟内异常几千 ...
- 6. Oracle闪回特性
Oracle 闪回 (flashback)是9i版本提供的新特性.这一特性:其他数据库(PostgreSQL,Mysql)是羡慕不已.对数据恢复提供非常便捷的方式.闪回技术通常用于快速简单恢复数据库中 ...
- Mac和Windows中常见中文字体的英文名称
我们在给HTML元素设置字体的时候经常会有类似 “ font-family:"微软雅黑", "黑体" ” 这样的写法,尤其是在使用Dreamweaver.Apt ...