You need to declare your different ssh keys in a ~/.ssh/config
file, as I explained in "How to manage multiple ssh keys in the ~/.ssh directory"
I would recommend not using the default name for the keys, but rather:
~/.ssh/proj1
~/.ssh/proj1.pub
~/.ssh/proj2
~/.ssh/proj2.pub
And then have a ~/.ssh/config
like:
Host ghproj1
User git
Hostname github.com
IdentityFile ~/.ssh/proj1
IdentitiesOnly yes
Host ghproj2
User git
Hostname github.com
IdentityFile ~/.ssh/proj2
IdentitiesOnly yes
You need to change the origin url in both repos:
cd /path/to/cloned/proj1
git remote set-url origin ghproj1:yourProject1
cd /path/to/cloned/proj2
git remote set-url origin ghproj1:yourProject2
See more at:
An url like ghproj1:yourProject1
is an ssh one which will explicitly use the key you specified in ~/.ssh/config
for the ghproj1
entry.
In the OP's case (answer below), the correct url would be:
~/.ssh/id_recaprojekt
Note: you need to specify the path to the private key (private, not public, not .pub
)
cd /path/to/cloned/plastickychirurg
git remote set-url origin plastickychirurg:michalfeher/plastickychirurg.git
cd /path/to/cloned/recaprojekt
git remote set-url origin recaprojekt:michalfeher/recaprojekt.git
Note that I have added "Hostname" in the Host entries.
The all idea of those entries in the ~/.ssh/config file is to not (repeat not) put git
or github.com
in the url (it is done for you by the items associated to each entries):
So:
git@github.com:michalfeher/recaprojekt.git
is the same as:
recaprojekt:michalfeher/recaprojekt.git
Except the second url will use the ssh key