Setting a variable for a given SSH host

ℝaphink asked:

In ssh_config, one can choose to export some environment variables to the host using SendEnv.

Is there also a way to force a given value for this variable, per host? For example, would it be possible to export variable $FOO with value bar only when connecting to host

My answer:

You can’t give a specific value for an environment variable in ssh_config, but you can certainly send the existing environment variable only to specific hosts.

    SendEnv FOO

To complete the chain:

FOO=bar ssh

Finally, the remote server must have the environment variable listed in AcceptEnv in its sshd_config.

AcceptEnv FOO

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.