SSH Config – How to Ignore Errors

opensshssh

I'm running an ubuntu image in a docker container, with my .ssh directory mounted from my native MacOs environment.

My .ssh/config file contains

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519_common

This works fine on a mac, but AddKeysToAgent and UseKeychain are not valid for linux, and anything (e.g. git) that uses the openssh-client package won't just ignore the unrecognised directives, but fail and exit.

Is there any way of having a .ssh/config file that will let me share it across mac and linux?

Best Answer

You can use the Match keyword in the ssh config file to restrict a portion of the configuration to only apply under certain conditions. For the excerpt in the question, something like the following should work:

Host *
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_ed25519_common

Match exec "uname -s | grep Darwin"
    UseKeychain yes

On a linux system, the grep will return failure (1), and so the following line(s) will be ignored; on the Mac host, the grep will return success (0) and the UseKeychain yes line will be applied.

The Match block is terminated by the next Match, Host, or end of file.

Note that AddKeysToAgent is not platform-specific, but is available in OpenSSH since version 7.2, so presumably you are using an older version of OpenSSH in the Ubuntu container but not on the Mac host.

Related Question