Multiple SSH keys for a single server

Published: Sep 08, 2017

Attempting to git clone:

Cloning into 'vagrant_vm'...
repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[Aim: create new key pair to access work bitbucket account]

Working from home, here’s how I went about setting up the environment on my personal Mac:
1. Created SSH key pair (bitbucket_work.pub, bitbucket_work)
2. Logged into my work bitbucket account and added the public key
3. Added the private key to the ssh agent (OS X)
4. Attempted to git clone and failed.

Turns out the git clone command would try using the private key associated with my personal bitbucket account. Tried vim ~/.ssh/config and added the lines but nothing.

Running ssh-add -l shows the agent’s loaded strings and there it was: the git clone using my personal key.

Carloss-iMac:Sites carlos$ ssh-add -l
2048 SHA256:xxxxxxxxxxxxxx /Users/carlos/.ssh/strasmore_byl (RSA)
2048 SHA256:xxxxxxxxxxxxxx /home/vagrant/.ssh/bitbucket_personal (RSA)
2048 SHA256:xxxxxxxxxxxxxx /Users/carlos/.ssh/2017FEB09_lithium_backyardlogs (RSA)
2048 SHA256:xxxxxxxxxxxxxx /Users/carlos/.ssh/lithium_lucs_17246 (RSA)
2048 SHA256:xxxxxxxxxxxxxx /Users/carlos/.ssh/bitbucket_work (RSA)

Ran ssh-add -D to clean out all keys.

Carloss-iMac:Sites carlos$ ssh-add -D
All identities removed.

Added the new private key to the agent (bitbucket_work) and ta-dah. Git clone works.

Last modified: September 8, 2017 1:23 pm
Posted in: Snippets