I have multiple ssh keys, using one key for one project. I have successfully assigned the public ssh keys to the relevant repositories inside my bitbucket account.
They are stored in the following location:
~/.ssh/rsa_generic_repos
~/.ssh/rsa_generic_repos.pub
~/.ssh/rsa_project1
~/.ssh/rsa_project1.pub
I then add these keys to my ssh-agent before attempting any git access:
ssh-add ~/.ssh/rsa_generic_repos
ssh-add ~/.ssh/rsa_project1
ssh-add -l - Displays:
4096 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXX Generic Repo Key (RSA)
4096 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXX Project 1 Key (RSA)
My Problem:
This works correctly (clones the repo):
git clone [email protected]:Myusername/generic-repo.com.git
This does not work:
git clone [email protected]:Myusername/project1.com.git
Error:
Cloning into 'project1'...
repository access denied. deployment key is not associated with the requested repository.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Yet if I run:
ssh-add -D
ssh-add ~/.ssh/rsa_project1
git clone [email protected]:Myusername/project1.com.git
It successfully clones the repo which it previously wouldn't. This suggests firstly that the public key is set up on bitbucket correctly and that the ssh daemon is not attempting to use any ssh key other than the first entry therefore resulting in the above error.
If anyone could help me with a way to get ssh to go through all the keys stored in the ssh-agent session I would be tremendously grateful.
Thank you for your help and time.
GIT_SSH_COMMAND="ssh -i /path/to/specific/key"
before the clone command (and don't start the ssh-agent on that tty). – Boiney