Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 example.com?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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.

Host example.com
    SendEnv FOO

To complete the chain:

FOO=bar ssh user@example.com

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

AcceptEnv FOO
share|improve this answer
    
Thanks. That's precisely what I'd like to avoid. –  ℝaphink Feb 27 '13 at 7:30
    
WHAT is precisely what you'd like to avoid? –  Michael Hampton Feb 27 '13 at 7:32
    
Having to write an alias in order to send a variable with a given value. –  ℝaphink Feb 27 '13 at 7:35
    
Sorry, not much else you can do... unless you can get the computer to read your mind. :) –  Michael Hampton Feb 27 '13 at 7:38
    
Thanks for confirming my suspicions though ;-) What I'd have liked would been something like SetVar FOO='bar' in ssh_config ;) –  ℝaphink Feb 27 '13 at 7:38

You can set per host config values using .ssh/config file. For example:

Host example.com
SendEnv FOO

Note that server must also support it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.