I have the ~/.ssh/config file I'm using to manage different keys from different hosts.

However, each time a new key is added, I'll need to also manually add this to ssh agent via ssh-add for separate reasons.

Is there a way this can be achieved automatically? if yes, how?

P.S: If it's any useful, I'm also using a macbook (osx)

  • I think that you are going to have to write some type of scripting to do this.
    – mdpc
    Mar 21, 2017 at 0:32

1 Answer 1


Implementing the case you specially worded in your question would be complicated and would require some bash scripting, which I don't recommend for such simple task.

But very similar thing can be achieved using AddKyesToAgent option in ssh_config, that will basically add the keys to ssh-agent when it is used for the first time. This option is available since OpenSSH 7.2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .