CodyK
CodyK

Reputation: 3667

AddKeysToAgent yes ssh config not working on Mac

Hi I have my ssh config file setup to auto add ssh keys to ssh agent. However, currently it is not working. It was working previously. I updated the ssh key for bitbucket and it no longer works. When I reboot, I have to add the ssh key manually using ssh-add -K option.

Can someone help me figure out why ssh config isn't working? AddKeysToAgent yes option is suppose to enable the auto adding of ssh keys.

I am running macOS Sierra 10.12.4

Here is config (I changed server names for sensitivity purposes)

GSSAPIAuthentication no

# --- SourceTree Generated ---
Host cik-bitbucket__com
    HostName bitbucket.com
    User cik
    PreferredAuthentications publickey
    IdentityFile /Users/cik/.ssh/cik-bitbucket__com
    UseKeychain yes
    AddKeysToAgent yes
# ----------------------------

Host *
    UseKeychain yes
    AddKeysToAgent yes
    ServerAliveInterval 15
    IdentityFile /Users/cik/.ssh/id_rsa

Host jenkins
    HostName pasjenkins1.mycompany.com
    UseKeychain yes
    AddKeysToAgent yes

Host jenkinsqa
    HostName pasjenkinsqa.mycompany.com
    UseKeychain yes
    AddKeysToAgent yes

Host artifactory
    HostName prp01
    UseKeychain yes
    AddKeysToAgent yes

Host bitbucket
    HostName bitbucket
    UseKeychain yes
    AddKeysToAgent yes

Host confluence
    HostName confluence01
    UseKeychain yes
    AddKeysToAgent yes

Host jira
    HostName jira01
    UseKeychain yes
    AddKeysToAgent yes

Host vagrant
    HostName 127.0.0.1
    Port 2222
    User vagrant
    IdentityFile /Users/cik/.vagrant.d/insecure_private_key

Host localhost
    HostName 127.0.0.1
    Port 2222
    User vagrant
    IdentityFile /Users/cik/.vagrant.d/insecure_private_key

Update:

Order matters.

This works

ssh-add -D
ssh-add -K /Users/cik/.ssh/cik-bitbucket__com
ssh-add
git push (Works)

Does not work

ssh-add -D
ssh-add
ssh-add -K /Users/cik/.ssh/cik-bitbucket__com
git push (Works)

Upvotes: 11

Views: 31734

Answers (1)

Jakuje
Jakuje

Reputation: 25966

You have got too many keys in your agent and only limited amount can be tried before rejecting by server. Fortunately, you have quite nice configuration distinguishing the keys per hosts, so you should be able to fix that by setting

IdentitiesOnly yes

configuration option in your ssh_config.

Upvotes: 15

Related Questions