How can I pass a value into an ssh command, such that the environment that is started on the host machine starts with a certain environment variable set to my choosing?

EDIT: The goal is to pass the current kde desktop ( from dcop kwin KWinInterface currentDesktop ) to the new shell created so that I can pass back an nfs locations to my JEdit instance on the original server which is unique for each KDE desktop. ( Using a mechanism like emacsserver/emacsclient)

The reason multiples ssh instances can be in flight at one time is because when I'm setting up my environment, I'm opening a bunch of different ssh instances to different machines.

link|improve this question

78% accept rate
feedback

2 Answers

up vote 1 down vote accepted

The ~/.ssh/environment file can be used to set variables you want available for remote commands. You will have to enable PermitUserEnvironment in the sshd configuration.

link|improve this answer
the variable needs to change potentially every ssh call – Ross Rogers Sep 29 '09 at 23:03
1  
Might be better to describe what you're trying to do and why. There could be other solutions. The environment file would have to be dynamically generated on each ssh call, which isn't impossible. – EmmEff Sep 29 '09 at 23:31
What is going to change? The values of those variables or even their names? – innaM Sep 30 '09 at 6:19
darn. I tried this solution, but I don't have access the sshd config file and putting vars in ~/.ssh/environment or ~/.ssh2/environment doesn't work. I guess I'm going to use a kludge where I leave this variable on an nfs disk and then snarf it up with my ~/.tcsh setup file. – Ross Rogers Sep 30 '09 at 18:46
This answer doesn't really seem to answer the question. – intuited Jun 17 '10 at 19:54
feedback

You can pass values with a command similar to the following:

ssh username@machine VAR=value cmd cmdargs

You can test with:

ssh machine VAR=hello env
link|improve this answer
Looks like that works well for bash environments. Too bad I'm in a corporate tcsh environment. – Ross Rogers May 21 at 21:45
feedback

Your Answer

 
or
required, but never shown

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