Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 502
CodyK Avatar asked Apr 13 '17 02:04

CodyK


People also ask

How do I enable ssh-agent on Mac?

There are two other ways you can enable SSH for macOS devices: Turn on SSH in the GUI by going to System Preferences > Sharing > Remote Login. Leverage the Commands tab in the JumpCloud Directory Platform to enable SSH across your fleet.

Where is ssh config on macOS?

ssh is a hidden folder in there but can be accessed normally via the command line. So you want something like <editor> /home/<user account name>/. ssh/config .

How do I access ssh folder on Mac?

ssh folder hidden. To see your . ssh folder in the Finder, press Command+Shift+G, then enter ~/. ssh .

Can ssh find config file Mac?

Where is the SSH configuration file? On macOS systems, the configuration file is found at “/private/etc/ssh/ssh_config,” which is symlinked to “/etc/ssh/ssh_config” for compatibility. A second, user-specific ssh_config is found at “~/.


1 Answers

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.

like image 147
Jakuje Avatar answered Sep 23 '22 06:09

Jakuje