简体   繁体   中英

Multiple git account doesn't work with Xcode

Due to my customer's privacy requirement, I've got create multiple account to access different git. With some helps, I've created the file config and multiple ssh keys in dir ~/.ssh . Using terminal, I've been able to perform all kind of action to the git . However, if I use XCode to perform those action, it stated that failed to authenticate .

xcode失败了

This is the content of ~/.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

Inside ~/.ssh/ , I've already had id_rsa , id_rsa.pub , acc2ssh , acc2ssh.pub . id_rsa is my usual git account, and acc2ssh is the other private account.

If I use terminal, it's alright, but it ask for passphrase everytime.

$ 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.

How do I config this to work in both xcode and terminal?

Additional question: How do I make the terminal to remember my passphrase?

UPDATE

Due to the confusion, I'll add more details about the git remote:

I'm checkout out the git via:

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

Because if I use the ssh provided from bitbucket, it won't work (access denied):

$ 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.

But Xcode seems to doesn't recognize the host bitbucket-myAccount2 as @Jakuje pointed out. Maybe I'm missing something here?

XCode (most probably) does not read your ~/.ssh/config because it is not based on OpenSSH. You should use just the hostname as it is and provide the correct private key.

If the other one (in default location) is still picked up, move it away/rename from default location ( ~/.ssh/id_rsa ) and update the ~/.ssh/config to reflect this change. For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM