多个git帐户不适用于Xcode

时间:2017-05-09 08:21:56

标签: xcode git macos ssh terminal

由于我的客户隐私要求,我创建了多个帐户来访问不同的git。通过一些帮助,我在dir config中创建了文件~/.ssh和多个ssh密钥。 使用终端,我已经能够对git执行各种操作。但是,如果我使用XCode执行这些操作,则表示failed to authenticate

xcode failed

这是~/.ssh/config

的内容
Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa

Host bitbucket-myAccount2
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/acc2ssh

~/.ssh/内,我已经有id_rsaid_rsa.pubacc2sshacc2ssh.pubid_rsa是我常用的git帐户,acc2ssh是另一个私人帐户。

如果我使用终端,它没问题,但每次都要求密码。

$ git remote -v
origin  git@bitbucket-myAccount2:privateTeam/project.git (fetch)
origin  git@bitbucket-myAccount2:privateTeam/project.git (push)

$ git pull
Enter passphrase for key '/Users/$myUser/.ssh/acc2ssh': 
Already up-to-date.

如何将其配置为在xcode和终端中工作?

其他问题:如何让终端记住我的密码?

更新

由于困惑,我将添加有关git remote的更多详细信息:

我通过以下方式查看了git:

$ git clone git@bitbucket-myAccount2:privateTeam/project.git

因为如果我使用bitbucket提供的ssh,它就不会工作(访问被拒绝):

$ git clone git@bitbucket.org:privateTeam/project.git
repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

但是Xcode似乎并没有像@Jakuje所指出的那样认出主持人bitbucket-myAccount2。也许我在这里错过了什么?

1 个答案:

答案 0 :(得分:0)

XCode(最有可能)不会读取您的~/.ssh/config,因为它不是基于OpenSSH。您应该只使用主机名并提供正确的私钥。

如果仍然选择了另一个(默认位置),请将其从默认位置(~/.ssh/id_rsa)移开/重命名,并更新~/.ssh/config以反映此更改。例如:

Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa2