【问题标题】:How to setup multiple identities of git ssh on windows?如何在 Windows 上设置 git ssh 的多个身份?
【发布时间】:2014-09-12 14:44:13
【问题描述】:

在我的 Windows 7 上,我创建了一个位于 .ssh 文件夹中的配置文件:-

Host office 
Hostname git@officeserver
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa 

Host home
Hostname git@myhome.net:8888
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_home

但是,我仍然无法克隆 repo。

  1. 想知道如何在 Windows 7 上设置多个主机?
  2. 配置文件的扩展名应该是什么?

【问题讨论】:

    标签: git ssh windows-7


    【解决方案1】:

    您的主机名设置错误,它不应该有用户名,只有主机名

    这里是一个例子,我使用 .ssh/config 在 github.com 上保存多个身份(每个身份都有不同的密钥对):

    
    #Default GitHub
    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
    Host github-companyname.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_companyname
    Host git.i411-companyname.com
      HostName git.i411-companyname.com
      User git
      IdentityFile ~/.ssh/id_rsa_companyname
    

    这是您的配置文件的外观:

    
    Host office 
    Hostname officeserver
    User git
    IdentityFile ~/.ssh/id_rsa 
    
    Host home
    Hostname myhome.net
    User git
    Port 8888
    IdentityFile ~/.ssh/id_home
    

    请注意,您不能在主机名中包含用户名或端口,您应该在不同的配置变量(UserPort)中指定它们

    【讨论】:

    • 嗨谢谢..还是同样的问题。问题:克隆时我需要对回购地址进行任何更改吗?
    • 您将其克隆为 git@office:path/to/repo 或 git@home:path/to/repo
    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2019-09-28
    相关资源
    最近更新 更多