Search code examples
gitsshgitosis

How can I designate a separate private key for each git repository I connect to?


I have multiple git repositories I need to connect to. For each one, the person in charge emailed me a public/private keypair to use to access the repository. I stored them in my .ssh directory along with my personal key:

$ ls ~/.ssh
id_rsa     id_dsa_site1    id_rsa_site2    id_rsa.pub
id_dsa_site1.pub    id_rsa_site2.pub

Then, I read some articles online that recommended I set up a config file, which I did:

$ cat ~/.ssh/config
Host site1.sub.domain.com
    User gitosis
    IdentityFile ~/.ssh/id_dsa_site1

Host git.site2.sub.domain.com
    User gitosis
    IdentityFile ~/.ssh/id_rsa_site2

However, when I try to clone the repos, I'm still being prompted for a password:

$ git clone gitosis@site1.sub.domain.com:myrepo.git
Initialized empty Git repository in /home/robert/myrepo/.git/
gitosis@site1.sub.domain.com's password: 

It looks like the key isn't associating properly. No google/so search I can think of is solving the problem. Any ideas?


Solution

  • Solution Found

    (for future people with this problem)

    Logging out and back in solved the problem for me.