Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active June 27, 2021 22:07
Show Gist options
  • Save CMCDragonkai/9199e2df8cf7ea1a45ff464a017c05be to your computer and use it in GitHub Desktop.
Save CMCDragonkai/9199e2df8cf7ea1a45ff464a017c05be to your computer and use it in GitHub Desktop.
SSH: Configuration Conditionals

SSH Configuration Conditonals

It's possible to conditionally set options in the ~/.ssh/config file.

For example, below shows the usage of a conditional setting of ControlMaster, which allows sharing of the SSH network port. But it doesn't work on Windows.

At ~/.ssh/config:

Match exec "~/.ssh/is-linux.sh"
    ControlMaster auto
    ControlPath /tmp/ssh-control:%h:%p:%r

At ~/.ssh/is-linux.sh:

#!/usr/bin/env bash

kernel_name="$(uname --kernel-name)"
[ "${kernel_name#*Linux*}" != "$kernel_name" ] && exit 0 || exit 1

Make sure to run chmod 700 ~/.ssh/is-linux.sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment