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

How can I ssh into a server and set an environment variable for the remote shell session? Ideally I'd like to control the name and value of the variable from the origin host.

share|improve this question

3 Answers 3

SSH into the machine and then run export SHELLVAR=value. Put that into the .bashrc for the account if you want to make it permanent.

share|improve this answer
    
or /etc/profile for a global export. –  David Rickman Aug 18 '09 at 3:44

Use "SendEnv" configuration variable of ssh. see man ssh_config for more information.

share|improve this answer
    
Interesting. Never knew about that configuration variable. Nice to learn something new! –  fpmurphy1 Aug 18 '09 at 14:03

If you're running a single-shot command on the remote side, something like this may work for you:

ssh user@remote "MYVAR=blah the_command -with args"

You can string multiple commands together as well:

ssh user@remote "export MYVAR=blah; one_command -with args && command2; command3"
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.