码迷,mamicode.com
首页 > 其他好文 > 详细

同一台电脑使用多个sshkey

时间:2015-09-02 18:34:47      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

参考链接:http://higrid.net/c-art-github_share_ssh.htm

http://yijiebuyi.com/blog/f18d38eb7cfee860c117d629fdb16faf.html

 

1、使用命令新建个ssh-key

tingdeMacBook-Pro:ContinuousIntegration ting$ ssh-keygen -t rsa -C xxxx@163.com

2、注意命令运行时输入新的文件名:

tingdeMacBook-Pro:ContinuousIntegration ting$ ssh-keygen -t rsa -C xxxx@163.com
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ting/.ssh/id_rsa): /Users/ting/.ssh/id_rsa_xxxx163_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/ting/.ssh/id_rsa_xxxx163_github.
Your public key has been saved in /Users/ting/.ssh/id_rsa_xxxx163_github.pub.
The key fingerprint is:……

3、默认SSH只会读取id_rsa,所以为了让SSH识别新的私钥,需要将其添加到SSH agent

ssh-add ~/.ssh/id_rsa_xxxx163_github
Identity added: /Users/ting/.ssh/id_rsa_xxxx163_github (/Users/ting/.ssh/id_rsa_xxxx163_github)

4、完成以上步骤后在~/.ssh目录创建config文件,该文件用于配置私钥对应的服务器。内容如下:

# Default github user(first@mail.com)

Host github.com
HostName github.com
 User git
 IdentityFile C:/Users/username/.ssh/id_rsa

# second user(second@mail.com)

Host github-second
 HostName github.com
 User git
 IdentityFile C:/Users/username/.ssh/id_rsa_second

5、Host随意即可,方便自己记忆,后续在添加remote是还需要用到。 配置完成后,在连接非默认帐号的github仓库时,远程库的地址要对应地做一些修改,比如现在添加second帐号下的一个仓库test,则需要这样添加:

git remote add test git@github-second:second/test.git #并非原来的git@github.com:second/test.git

注意: github根据配置文件的user.email来获取github帐号显示author信息,所以对于多帐号用户一定要记得将user.email改为相应的email(second@mail.com)。

 

同一台电脑使用多个sshkey

标签:

原文地址:http://www.cnblogs.com/LemonTing/p/4779183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!