I have a personal account and a company account on Unfuddle. On Unfuddle SSH keys can only be used on a single account, so I need to create a seperate SSH key on my laptop for both accounts. I ran ssh-keygen -t rsa to generate two keys with different names (personal is default name and company is {company}_rsa). The problem now is that it appears that my default key is used everywhere and I can't find out how to specify a key to use in Git for individual repos.

So my question is: How do I specify an SSH key to use on a repo-to-repo basis?

I setup my ssh_config (~/.ssh/config) but it still doesn't seem to work.

config:

Host {personalaccount}.unfuddle.com
     HostName {personalaccount}.unfuddle.com
     User git
     IdentityFile /Users/dave/.ssh/id_rsa

Host {companyaccount}.unfuddle.com
     HostName {companyaccount}.unfuddle.com
     User git
     IdentityFile /Users/dave/.ssh/cage_rsa

My Git repo config file for a repo on my company unfuddle account looks like this:

[remote "origin"]
     url = git@{companyaccount}.unfuddle.com:{companyaccount}/overall.git
     fetch = +refs/heads/*:refs/remotes/origin/*

So I am not sure if there is something wrong with my ssh config or my git config.

link|improve this question
1  
For the people voting to close this, I would like to know why. – Dave Long Apr 18 '11 at 14:55
Your ssh config looks right, I'm using a similar configuration. – PaĆ­lo Ebermann Apr 18 '11 at 15:39
feedback

migrated from stackoverflow.com Apr 18 '11 at 19:24

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 23 down vote accepted

If you have an active ssh-agent that has your id_rsa key loaded, then the problem is likely that ssh is offering that key first. Unfuddle probably accepts it for authentication (e.g. in sshd) but rejects it for authorization to access the company repositories (e.g. in whatever internal software they use for authorization, possibly something akin to Gitolite). Perhaps there is a way to add your personal key to the company account (multiple people are not sharing the same corp_rsa public and private key files, are they?).


The IdentitiesOnly .ssh/config configuration keyword can be used to limit the keys that ssh offers to the remote sshd to just those specified via IdentityFile keywords (i.e. it will refuse to use any additional keys that happen to be loaded into an active ssh-agent).

Try these .ssh/config sections:

Host {personalaccount}.unfuddle.com
     IdentityFile ~/.ssh/id_rsa
     IdentitiesOnly yes

Host {companyaccount}.unfuddle.com
     IdentityFile ~/.ssh/{companyaccount}_rsa
     IdentitiesOnly yes

Then, use Git URLs like these:

git@{personalaccount}.unfuddle.com:{personalaccount}/my-stuff.git
git@{companyaccount}.unfuddle.com:{companyaccount}/their-stuff.git

If you want to take full advantage of the .ssh/config mechanism, you can supply your own custom hostname and change the default user name:

Host uf-mine
     HostName {personalaccount}.unfuddle.com
     User git
     IdentityFile ~/.ssh/id_rsa
     IdentitiesOnly yes

Host uf-comp
     HostName {companyaccount}.unfuddle.com
     User git
     IdentityFile ~/.ssh/{companyaccount}_rsa
     IdentitiesOnly yes

Then, use Git URLs like these:

uf-mine:{personalaccount}/my-stuff.git
uf-comp:{companyaccount}/their-stuff.git
link|improve this answer
3  
If you have multiple accounts on the same Unfuddle subdomain (with different SSH keys), you will need to use the second method. – leolobato Dec 20 '11 at 18:25
feedback

man ssh_config

Something like

Host personal_repo
  User personal
  IdentityFile .ssh/personal_rsa

Host company_repo
  User company
  IdentityFile .ssh/company_rsa

And use personal_repo as host in your git repo.

link|improve this answer
Tass, could you review my changes made above? I added my ssh_config and my git config. – Dave Long Apr 18 '11 at 14:55
Host is just an identifier - no need for full domain name. That probably creates some hidden bugs. If you change that, you don't need to spell the full name in your git config. – Tass Apr 18 '11 at 15:18
for gitorious, user = git and host gitorious.org: e.g. git@gitorious.org:~revelut/qt/bruce-sandbox-qt.git How do you match in your Host a part of the url ? (typically ~revelut for me) – Bruce Apr 18 '11 at 15:53
@Tass so if I give the name company_unfuddle to the SSH config should my URL be git@company_unfuddle:{company}/overall.git? @Bruce - I am not sure what you are asking. Could you expand a little more? – Dave Long Apr 18 '11 at 18:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.