Can I ignore errors in my ssh config?

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.


You should use the IgnoreUnknown directive early on in your ~/.ssh/config:

IgnoreUnknown   UseKeychain,AddKeysToAgent

From the ssh_config(5) manpage:

IgnoreUnknown

Specifies a pattern-list of unknown options to be ignored if they are encountered in configuration parsing. This may be used to suppress errors if ssh_config contains options that are unrecognised by ssh(1). It is recommended that IgnoreUnknown be listed early in the configuration file as it will not be applied to unknown options that appear before it.


On all versions of openssh I could test, a failing Match condition will not prevent ssh from erroring out on any following directives unknown to it:

$ cat ~/.ssh/config
Match !all
        Foobar yes
$ ssh localhost
/home2/ahq/.ssh/config: line 2: Bad configuration option: foobar
/home2/ahq/.ssh/config: terminating, 1 bad configuration options

Tags:

Ssh

Openssh