客户端配置多个git账号,实现多个服务器免密钥

我有两个git账号,一个是公司的,一个是开源中国的,

公司的git账号是:TSKY.qiao.yuan  对应的服务器是192.168.2.250

开源中国的git账号是:mkl34367803@163.com      对应的服务器是git.oschina.net


1:首先进入这个目录C:\Users\yuanqiao\.ssh     然后右键git bash here(前提是你安装了git客户端)


2:新建ssh key

ssh-keygen -t rsa -C "TSKY.qiao.yuan"
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa

ssh-keygen -t rsa -C "mkl34367803@163.com"  
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_oschina

生成两个私钥和公钥,如下所示:


id_rsa是公司git账号的私钥,也是git默认读取的私钥文件,


3:将新的私钥加入到ssh agent

因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:

ssh-add ~/.ssh/id_rsa_oschina

如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:

ssh-agent bash
ssh-add ~/.ssh/id_rsa_oschina

4:为了将开源中国的私钥也加入到客户端,我们需要新建一个config文件,如上图所示。

touch config        # 创建config


5:conf的文件内容如下:

# 该配置用于工作  
# Host 服务器别名  
Host  192.168.2.250 
# HostName 服务器ip地址或机器名  
HostName 192.168.2.250 
# User连接服务器的用户名  
User TSKY.qiao.yuan  
# IdentityFile 密匙文件的具体路径  
IdentityFile C:\Users\yuanqiao\.ssh\id_rsa  
  
  
# 该配置用于个人 github 上  
# Host 服务器别名  
Host git.oschina.net  
# HostName 服务器ip地址或机器名  
HostName git.oschina.net  
# User连接服务器的用户名  
User mkl34367803@163.com  
# IdentityFile 密匙文件的具体路径  
IdentityFile C:\Users\yuanqiao\.ssh\id_rsa_oschina

6:将公钥保存到自己公司的git服务器上和开源中国。

也就是分别将id_rsa.pub和id_rsa_oschina.pub的内容分别拷贝到公司的服务器和自己的开源中国服务器上。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值