多github帐号的SSH key切换
我有两个github帐号,一个是个人所用,一个是为公司项目所用。如果是单用户(single-user),很方便,默认拿id_rsa与你的github服务器的公钥对比;如果是多用户(multi-user)如user1,user2,那么就不能用在user2的身上了,这个时候就要配置一下了:
1、新建user2的SSH Key
#新建SSH key:
$ cd ~/.ssh # 切换到C:\Users\Administrator\.ssh
ssh-keygen -t rsa -C "mywork@email.com" # 新建工作的SSH key
# 设置名称为id_rsa_work
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_work
2、新密钥添加到SSH agent中
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
ssh-add ~/.ssh/id_rsa_work
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
ssh-agent bash
ssh-add ~/.ssh/id_rsa_work
3、修改config文件
在~/.ssh目录下找到config文件,如果没有就创建:
touch config # 创建config
然后修改如下:
我的config配置如下:
# 该文件用于配置私钥对应的服务器
# Default github user(first@mail.com)
Host github.com
HostName github.com
User git
IdentityFile C:/Users/Administrator/.ssh/id_rsa
# second user(second@mail.com)
# 建一个github别名,新建的帐号使用这个别名做克隆和更新
Host github2
HostName github.com
User git
IdentityFile C:/Users/Administrator/.ssh/id_rsa_work
如果存在的话,其实就是往这个config中添加一个Host:
#建一个github别名,新建的帐号使用这个别名做克隆和更新
Host github2
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa2
其规则就是:从上至下读取config的内容,在每个Host下寻找对应的私钥。这里将GitHub SSH仓库地址中的git@github.com替换成新建的Host别名如:github2,那么原地址是:git@github.com:funpeng/Mywork.git,替换后应该是:github2:funpeng/Mywork.git.
4、打开新生成的~/.ssh/id_rsa2.pub文件,将里面的内容添加到GitHub后台。
可不要忘了添加到你的另一个github帐号下的SSH Key中。
5、测试:
Administrator@FANGPENG /e/work
$ ssh -T git@github.com
Hi BeginMan! You've successfully authenticated, but GitHub does not provide shel
l access.
Administrator@FANGPENG /e/work
$ ssh -T github2
Hi funpeng! You've successfully authenticated, but GitHub does not provide shell
access.
6、应用
测试成功,那么我尝试在我的work目录下克隆我@126.com账号下的远程仓库。如下:
Administrator@FANGPENG /e/work
$ git clone github2:funpeng/Mywork.git
Cloning into 'Mywork'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done
克隆成功,大功告成了!
感谢参考:
3.git.md
多github帐号的SSH key切换的更多相关文章
- 多个github帐号的SSH key切换
写在前面的话 github账号,工作有一个,自己有一个.但是默认下使用ssh key在git push时只有默认账号能免输入账号和密码. 如果想让另一个账号在代码push时免账号和密码,请看这篇文章h ...
- 为github帐号添加SSH keys
为github帐号添加SSH keys 2012-05-26 00:05 34279人阅读 评论(6) 收藏 举报 ssh文本编辑gitvim工具up 使用git clone命令从github上同步g ...
- 为github帐号添加SSH keys(Linux和Windows)
文章转自:https://blog.cofface.com/archives/406.html/2 一.Linux增加ssh keys方法: 使用git clone命令从github上同步github ...
- CentOS7上GitHub/GitLab多帐号管理SSH Key
由于公司团队使用 GitLab 来托管代码,同时,个人在 Github 上还有一些代码仓库,可公司邮箱与个人邮箱是不同的,由此产生的 SSH key 也是不同的,这就造成了冲突 ,文章提供此类问题的解 ...
- 为GitLab帐号添加SSH keys并连接GitLab
https://blog.csdn.net/xyzchenxiaolin/article/details/51852333 为github帐号添加SSH keys使用git clone命令从GitLa ...
- 添加SSH keys到github帐号
使用git clone命令从github上同步github上的代码库时,如果使用SSH链接(如我自己的esesgrid项目:git@github.com:hmilycc/esesgrid.git),而 ...
- GitHUB帐号申请及相关操作
GitHUB帐号申请及相关操作 GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub.GitHub 于 2008 年 4 月 10 ...
- github with msysgit:配置SSH Key
Step 1: Check for SSH keys First, we need to check for existing ssh keys on your computer. Open up G ...
- GitHub秘钥(SSH Key)
一.公钥的作用 公钥一般给服务器,别人权限中加入我给的公钥,当我们从远地仓库中下载项目(git clone xxx)的时 那个服务器通过他的绑定的公钥来匹配我的私钥,如果匹配,则就可以正常下载,如果不 ...
随机推荐
- 【Linux】- Ubuntu安装redis,并开启远程访问
Ubuntu16.04安装Redis 开启Redis远程访问的步骤: 1.注释掉redis配置文件中的,bind 127.0.0.1 sudo vi /etc/redis/redis.conf #注释 ...
- PHPcmsv9 还原数据库 操作步骤
相比dedecms,相同之处:模版好制作,都是开源.不同之处:pc貌似有更好的 负载能力. 言归正传,这两天在捣鼓phpcmsv9程序,但是本地调试好了之后,无论是通过打包方式,还是 转移数据的方式. ...
- JQuery 学习笔记--02
JS 中的 window.onload() 方法与 Jquery 中的 $(document).read(function( ){ }) 的区别 : 加载时机不一样, window.onload() ...
- InstallShield Limited Edition for Visual Studio 国内注册时国家无下拉框解决方法
注册地址:http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visual-Studio 火狐 ...
- Spring MVC架构浅析
阅读目录 Spring MVC概述 Spring MVC框架的特点 Spring MVC工作原理 Spring MVC概述 Spring的web框架围绕DispatcherServlet设计,Disp ...
- Lucene笔记二
lucene 的排序 package cn.itcast.lucene; import java.io.IOException; import org.apache.lucene.document.D ...
- 【hdu3555】Bomb 数位dp
题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...
- vdbench和fio测试磁盘性能的对比总结
一.安装 1.安装vdbench,首先安装java:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...
- queue队列
1.作用:解耦,提高效率.队列就是一个容器,一个有顺序的容器. q.queue.Queue(maxsize=3): 生成一个队列的实例,并且最多存储3个元素 q.get(item,block=Ture ...
- Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...