OpenSSH – Have SSH Add Keys to Agent as Needed

key-authenticationssh

When I ssh into a server and my key isn't loaded in the agent, I have to abort, then run ssh-add to get my key into the agent. I'd like the ssh command to add the key automatically if it isn't present, though. Is this possible?

Best Answer

The AddKeysToAgent option does what I want. I can specify -o AddKeysToAgent=yes on the command line or add AddKeysToAgent yes on a line by itself in my .ssh/config. Either works.

It looks like this is a very recent addition to openssh, appearing in release 7.2, dated 2016-02-28!

http://www.openssh.com/txt/release-7.2

Thanks, OpenBSD! I'll be using this a lot.

Related Question