Lulzim Fazlija
Lulzim Fazlija

Reputation: 885

How do I manage multiple ssh keys to be used on two different private repository in GIT

I have two private repositories on git and I have added key on each of them on the 'Deploy keys' section, but the thing is now I am having trouble Git recognizing my kyes on my machine.. I have two public/private pair key for both of repositories... id_rsa.pub, id_rsa and id_rsa2.pub, id_rsa2.

From one project it works good, while from the other one it does not work push or pull, it does not even recognise my password, seems like from any project I am Git is using always id_rsa.pub file.

To make it clear my question is, How can I specify keys to be configured based on projects, like if I am in Project 'X' use id_rsa.pub while If I am in 'Y' project use id.rsa2.pub

Any solution?

Upvotes: 0

Views: 256

Answers (1)

Alex028502
Alex028502

Reputation: 3824

If these repositories are not on github, adjust accordingly...

I have this in my ~/.ssh/config

Host github-as-id1
  HostName github.com
  User git
  IdentityFile /home/me/.ssh/_id_rsa
  IdentitiesOnly yes
Host github-as-id2
  HostName github.com
  User git
  IdentityFile /home/me/.ssh/id_rsa2
  IdentitiesOnly yes

then in my .git/config in the project I ahve

[remote "origin"]
  url = ssh://git@github-as-id1/user/project.git
  fetch = +refs/heads/*:refs/remotes/origin/*

The username is there twice. I think you could get rid of either "git@" from .git/config or User git from .ssh/config

Upvotes: 1

Related Questions