[BUG] Git is not using the configured SSH key when there is another SSH key added to the SSH agent
- From
Utku <ugultopu@gmail.com>
- Date
- Mar 27, 2021, 18:31 UTC
- Message-ID
- <967BFF88-A8E1-4EEC-B298-668012E42C03@gmail.com>
# Versions
- Git 2.30.1 - macOS 10.15.7
# Steps to Reproduce
- Have two SSH key pairs on your machine, one with a passphrase and other without. The keys were created by running `ssh-keygen` in my case.
- Add the key with a passphrase to the SSH agent by running `ssh-add` and entering the passphrase.
- Have an entry like the following in your `~/.ssh/config`:
Host someName
HostName bitbucket.org
User git
IdentityFile ~/.ssh/private-key-of-the-pair-without-a-passphrase- Add the public key of the pair without a passphrase to your BitBucket account.
- Run `git clone someName:path/to/your/repository.git`. You will get a not authorized error. As far as I can tell, this means that Git has tried to use the key with the passphrase (which is added to the SSH agent). Since this key is **not** the key that was added to the BitBucket account, we received a not authorized error.
- Add the key without a passphrase to your SSH agent by running `ssh-add` and try the same command (`git-clone`) again. It will work.
- Now, remove both keys from the SSH agent by running `ssh-add -D` and try and try the same command (`git-clone`) again. It will still work.
I didn't test but don't believe this has something to do with the key having a passphrase or not. Also, I believe that I'm not using macOS Keychain to store the decrypted keys.
# Expected Behavior
The `git-clone` command to work as expected, regardless of which keys are present in the SSH agent, since the information that I provide to Git (via the `Host` information in the `~/.ssh/config` file) is sufficient.
# Actual Behavior
Git is trying to use the SSH key that is present in the SSH agent, instead of using the SSH key which is explicitly declared in the `~/.ssh/config` file.