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

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 [email protected]:Company/testing.git
git push origin master

Note that, this time, rather than pushing to [email protected], we‘re using the custom host that we create in the
config file: [email protected]

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!

时间: 2024-07-31 04:37:57

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

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

Step 1 - Create a New SSH Key We need to generate a unique SSH key for our second GitHub account. 1 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 prompte

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

1.生成一个新的自定义名称的公钥: ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/sxfself 一直点击回车 执行命令后,生成命名的公钥和生成默认公钥的步骤一样. 执行完成后,会在 ~/.ssh/目录下生成一个 sxfself 和 sxfself.pub 文件 2.在 SSH 用户配置文件 ~/.ssh/config 中指定对应服务所使用的公秘钥名称,如果没有 config 文件的话就新建一个,并输入以下内容: #sxfSelf

如何在一台机子上配置两个github

前几天,有这么一个需求,自己的域名网站都已搭好,却发现代码无法上传的阿里云,查看原因是之前电脑配置了个公司的阿里云私钥,使用了git的默认配置方式,直接生成的ssh key,而当一台机子上想要上传两个git地址的时候,却不能这样,必须增加~./ssh下的config文件,话不多说,上代码 第一 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 } span.s1 { } #default work

如何在一台机器上配置多个git的rsa

如何在一台机器上配置多个git的rsa 问题的提出 很多时候,我们一台机器上要使用多个git库,比如 github, csdn 以及 自己公司的.那么 rsa就要有多份.那么该如何让这些共同存在呢? 原理就是:建立多个不同的rsa 然后 在ssh config中分别不同的配置. 具体步骤 1 建立rsa ssh-keygen -t rsa -C "你的邮箱地址" 执行完这条命令之后, 会弹出如下提示: Enter file in which to save the key (/User

MySQL集群搭建(所有节点在同一台机子上)

转自:http://www.2cto.com/database/201408/328954.html 加了一些遇到的错误及其解决方法: ------------------------------------------------华丽的分割线-------------------------------------------------------- mysql用来开发中小型项目还是挺好用的,从节约成本的方面来考虑的确是个不错的选择,但是开发并发了比较大的项目显然还是有些吃力的,前几 年解决

一台机子上运行使用不同Java版本的多个tomcat

方法:在tomcat/bin/下创建setenv.sh并写入 export JAVA_HOME=/usr/share/jvm/jdk1.8.0_91 When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE. 即启动tomcat时会先在bin/下找setenv.sh,如果

如何在一台机子上启动两个TOMCAT

同时启动两个tomcat设置,具体如下: 1.不要设置CATALINA_HOME 2.分别修改安装目录下的conf子目录中的server.xml文件: a.修改http访问端口为不同的端口,将8080修改为tomcat不在使用的端口号.此处所设的端口号即是以后访问web时所用的端口号. b.修改其中一个tomcat的Shutdown端口(在server.xml中,默认为8005端口),将8005修改为没有在使用的端口号,例如8055. c.修改其中一个tomcat的8009端口,将8009修改为

在一台机子上,安装,运行两mysql数据库实例

为了方便测试,想要用到两个mysql数据库实例.以windows系统为例 当然安装第一个mysql数据库,很简单没什么说的.但是再要安装,运行mysql安装程序时,会提示,修复,卸载,重新安装. 这时需要下载一个免安装的mysql,zip文件的. 到点击打开链接选择,ZIP Archive格式的下载,根据系统选择32,64位 的. 我下载的是,mysql-5.5.20-winx64,下载后解压得到一个mysql-5.5.20-winx64文件夹, 里面没有my.ini文件,但是有很多不同的.in

个人开发者帐号--我是如何实现在另一台mac上真机调试的

本文转载至 : http://blog.csdn.net/chenyong05314/article/details/8689534 注:本人有一台mac电脑,之前申请开发者帐号的时候直接就是在这台机子上弄的,今天去公司第一天上班,公司又配了一台更爽的mac pro电脑,所以想在新电脑上实现真机调试,主要就两步吧: 1.钥匙串访问最下边有一栏“证书”  -->右键导出 2.钥匙串访问最上边登录那一栏(非“密钥”一栏)找到你的密钥导出 然后把两个文件传到新电脑上,均为双击即可