同时管理多个 SSH 私钥, 可以实现同时使用多个 git 源管理工具


同一台电脑关于多个SSH KEY管理

一介布衣 2013-10-02 linux 5221

使用环境:关于同一台电脑LInux系统下使用多个SSH key 切换使用(或者多用户使用ssh提交代码)

要求,可以创建不同的 PUBLIC KEY ,根据下面步骤设置.

(1)比如有aaa,bbb,ccc 三个帐号需要生成不同的 PUBLIC KEY

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa_aaa.
Your public key has been saved in /root/.ssh/id_rsa_aaa.pub.
The key fingerprint is:
9b:92:f6:1f:d2:72:bd:72:19:45:42:5f:e4:65:33:64 root@AY140122145815620396Z
The key's randomart image is:
+--[ RSA 2048]----+
|           .. .E=|
|            ..o++|
|             o. .|
|              .  |
|        S    .   |
|       . + ..    |
|      + = + .o   |
|     . o +..o.   |
|        ...o.    |
+-----------------+

 进过上面的shell 我们在 /root/.ssh/ 目录下创建 id_rsa_aaa  私钥 和 id_rsa_aaa.pub 公钥

注意这里

Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaa  #设置路径,如果不设置默认生成 id_rsa  和  id_rsa.pub

(2)按照上面的步骤逐个生成 bbb 和 ccc 对应的公钥和私钥 ........

(3)查看系统ssh-key代理,执行如下命令

$ ssh-add -l
Could not open a connection to your authentication agent.
如果发现上面的提示,说明系统代理里没有任何key,执行如下操作
exec ssh-agent bash

如果系统已经有ssh-key 代理 ,执行下面的命令可以删除

$ ssh-add -D


(4)把 .ssh 目录下的3个私钥添加的 ssh-agent

$ ssh-add ~/.ssh/id_rsa_aaa
$ ssh-add ~/.ssh/id_rsa_bbb
$ ssh-add ~/.ssh/id_rsa_ccc

依次执行上面三条shell 把三个私钥添加到 ssh-key 代理里面

(5)打开github 或者 开源中国 ssh 管理页面把 对应的公钥提交保存到代码管理服务器 (.pub 结尾)

(6)在 .ssh 目录创建 config 配置文件

nano ~/.ssh/config

输入如下配置信息

#aaa  (github 配置)
Host aaa
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_aaa

#bbb  (开源中国 配置)
Host bbb
    HostName git.oschina.net
    User git
    IdentityFile ~/.ssh/id_rsa_bbb

#ccc
........

(6)记住上面一步 Host 里设置的别名,开始克隆项目,以开源中国为例

git clone git@git.oschina.net:userName/projectName.git

到此为止多个ssh-key 已经可以同时使用.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值