Step 1 - Create a New SSH Key
We need to generate a unique SSH key for our second GitHub account.

ssh-keygen -t rsa -C "your-email-address"

Be careful that you don't over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY. In my case, I've saved the file to~/.ssh/id_rsa_nettuts.

Step 2 - Attach the New Key
Next, login to your second GitHub account, browse to "Account Overview," and attach the new key, within the "SSH Public Keys" section. To retrieve the value of the key that you just created, return to the Terminal, and type: vim ~/.ssh/id_rsa_COMPANY.pub. Copy the entire string that is displayed, and paste this into the GitHub textarea. Feel free to give it any title you wish.

Next, because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal, type: ssh-add ~/.ssh/id_rsa_COMPANY. If successful, you'll see a response of "Identity Added."

Step 3 - Create a Config File
We've done the bulk of the workload; but now we need a way to specify when we wish to push to our personal account, and when we should instead push to our company account. To do so, let's create a config file.

touch ~/.ssh/config
vim config

If you're not comfortable with Vim, feel free to open it within any editor of your choice. Paste in the following snippet.

#Default GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

This is the default setup for pushing to our personal GitHub account. Notice that we're able to attach an identity file to the host. Let's add another one for the company account. Directly below the code above, add:

Host github-COMPANY
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_COMPANY

This time, rather than setting the host to github.com, we've named it as github-COMPANY. The difference is that we're now attaching the new identity file that we created previously: id_rsa_COMPANY. Save the page and exit!

Step 4 - Try it Out
It's time to see if our efforts were successful. Create a test directory, initialize git, and create your first commit.

git init
git commit -am "first commit'

Login to your company account, create a new repository, give it a name of "Test," and then return to the Terminal and push your git repo to GitHub.

git remote add origin git@github-COMPANY:Company/testing.git
git push origin master

Note that, this time, rather than pushing to git@github.com, we're using the custom host that we create in the
config file: git@github-COMPANY.

Return to GitHub, and you should now see your repository. Remember:

When pushing to your personal account, proceed as you always have.
For your company account, make sure that you use git!github-COMPANY as the host.
Be sure to refer to the screencast if you need a more visual overview of the steps above!

linux同一台机子上用多个git 账号的更多相关文章

  1. 同一台机子上用多个git 账号

    Step 1 - Create a New SSH Key We need to generate a unique SSH key for our second GitHub account. 1 ...

  2. 【git】一台机器上使用不同的git账号

    1.生成一个新的自定义名称的公钥: ssh-keygen -t rsa -C "shangxiaofei3@163.com" -f ~/.ssh/sxfself 一直点击回车 执行 ...

  3. windows系统一台电脑先后添加多个git账号

    概述 电脑上已经配置了github的ssh连接.现在又有一个不同的git账户,也就是要在一台电脑上配置两个git账号. 下面记录一下我配置的方法. 一.取消git全局配置 之前配置github的时候, ...

  4. SQL2000,2005,2008安装在一台机子上

    工欲善其事,必先利其器.本机的系统是在网上自己下载的,是32位windows7旗舰版.因为学习,需要在一台机子上同时安装SQL Server2000,2005,2008三个版本的数据库.先是在网上查了 ...

  5. git学习笔记:一台电脑上配置两个git账户

    如何在一台电脑上配置两个git账户,现在云端仓库很多,有开源中国的 gitee.com 微软的 github.com 还有 gitlab.com 和 bitbucket.org 等等,下面是具体步骤 ...

  6. 简易搭建git仓库、关联远程和本地仓库方法。克隆仓库方法。同一台电脑上创建两个git ssh key方法。

    一,在github上建仓库 react-js-antd-demo: 二:将远程仓库与本地仓库关联 git remote add origin git@github.com:begin256/react ...

  7. 四步实现在一台电脑上使用多个github账号

    四步实现在一台电脑上同时使用多个GitHub账号 今天和大家聊一下如何在一台电脑上同时使用多个GitHub账号,通过以下四个步骤就可以实现,其中第二个步骤为了便于叙述分成了几个小步骤. 1. 取消全局 ...

  8. Git 在同一台机器上配置多个Git帐号

    在同一台机器上配置多个Git帐号 By:授客 QQ:1033553122 实践环境 win10 Git-2.21.0-64-bit.exe TortoiseGit-2.8.0.0-64bit.msi ...

  9. 一台电脑上配置多个git的ssh key

    前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...

随机推荐

  1. n阶汉诺塔 记住吧。。

    #include "bits/stdc++.h" using namespace std; int c; void move(char a,int n,char b) { prin ...

  2. html5-磊哥

    <!doctype html><html lang="en">    <head>        <meta charset=" ...

  3. sql server中如何将两个字段数据合并成一个字段显示(字段与字段添加特殊符号)

    之前,我在做统计数据时,需要一个字段显示某月的订单数量和订单金额,要求组合成一个字段,用括号组合. 统计出来的结果大概是这样的,首先我们来创建一些模拟数据 ---创建订单表--- create tab ...

  4. Awk 从入门到放弃(3) —- 内置变量

    转:http://www.zsythink.net/archives/1374 NF :当前行的字段个数 NR:  行号 FNR: 各文件分别计数的行号 RS: 输入行分隔符 ORS:输出行分隔符 内 ...

  5. hadoop kafka install (6)

    reference: http://kafka.apache.org/quickstart  http://dblab.xmu.edu.cn/blog/1096-2/ hadoop@iZuf68496 ...

  6. C#阿里云 移动推送 接入

    接入阿里云的 移动推送 SDK,实现在后台直接 发送消息给APP的功能.        ----------------OpenAPI进行推送 2.0高级接口 阿里云配置准备:1.移动app配置:打开 ...

  7. re 正则

      如果直接给出字符,就是精确匹配.对于特殊字符- ,在正则表达式中要用转义字符\转义.   \d        一个数字, \w       任意单个字符,空白符除外(例 字母.数字或下划线 . 英 ...

  8. 百视通与微软共同宣布9月在华发布Xbox One

    4月30日消息,百视通今日与微软共同宣布,于今年9月在华发布Xbox One.这是继百视通与微软2013年9月成立合资公司后,双方合作的又一进展. 微软副总裁,硬件及设计工作室部门主管尤瑟夫 •梅赫迪 ...

  9. Free 4 months Serial License Key Of Outpost Security Suite Pro 8.1

    VISIT HEREto gey a 1 year key.... for the latest version Promo code ? well use the same here too : C ...

  10. Andriod Studio 解决问题 Failed to resolve: com.android.support:appcompat-v7:28.+

    Andriod Studio报错提示: Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:28.+ 原因:Andri ...