Home » Questions » Computers [ Ask a new question ]

How can I pass an environment variable through an ssh command? [duplicate]

How can I pass an environment variable through an ssh command? [duplicate]

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?

Asked by: Guest | Views: 381
Total answers/comments: 2
bert [Entry]

"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.

Variables set this way are exported to child processes, so you can:

echo ""Foo=Bar"" > sshenv
echo ""Joe=37"" >> sshenv
scp sshenv user@server:~/.ssh/environment
ssh user@server myscript

and myscript will know that Foo is Bar and Joe is 37."
bert [Entry]

"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

On tcsh the following seems to work:

ssh machine ""setenv VAR <value>; printenv"""