I'm using a product called vlad which is making non-interactive ssh connections to my Ubuntu server but the problem is that it can't see any of the environment variables.

I've been googling like crazy but can't find a solution. I've tried adding the variables to an .ssh/environment file for the user on my server and also changing the settings in /etc/ssh/sshd_config but no joy.

Can anyone help?

Cheers,

Chris

link|improve this question

56% accept rate
feedback

6 Answers

Check you /etc/ssh/ssh_config (on client) and look at SendEnv option. In my case, I have SendEnv LANG LC_*.

There is some interresting informtions in the man ssh_config

link|improve this answer
Thanks for the response Dom, sorry my question wasn't very clear I was really looking for a solution on the server so I don't need to setup something on each client. – ChrisInCambo Feb 4 '10 at 8:52
1  
Unfortunately, the client doesn't send environment variables unless you tell it which ones to send. If you have many clients to setup, you might consider using a tool to deploy your SSH client configuration, such as puppet. – Raphink Feb 4 '10 at 10:56
feedback

Do you have the environmental variables defined in ~/.bashrc on the server? Sometimes somethings read ~/.profile instead. One trick I do is to symlink ~/.profile to ~/.bashrc,

e.g.:

ln -s ~/.bashrc ~/.profile
link|improve this answer
That didn't work – ChrisInCambo Feb 4 '10 at 12:45
feedback

What is the username that vlad connects as? What is the shell for this user? Can you set the shell to a wrapper that sets your environment variables?

link|improve this answer
feedback

my guess is your environment variables are in the wrong file. there are two different files which get sourced for login/interactive shells.

take a look at this post:
http://serverfault.com/questions/8882/what-is-the-difference-between-a-login-and-an-interactive-bash-shell

EDIT: ok, now for non-interactive logins:
are you login in with a key? when yes, you can add this to your authorized_keys file:

environment="NAME=value"
         Specifies that the string is to be added to the environment when logging in using this key.  Environment variables set this way override other
         default environment values.  Multiple options of this type are permitted.  Environment processing is disabled by default and is controlled via
         the PermitUserEnvironment option.  This option is automatically disabled if UseLogin is enabled.

(from man sshd)

link|improve this answer
I'm interested in non-interactive shells – ChrisInCambo Feb 4 '10 at 12:46
sorry, haven't read this. i've edited my answer accordingly. – Christian Feb 4 '10 at 13:54
No that didn't work either. – ChrisInCambo Feb 5 '10 at 1:56
feedback

If you have control of the ssh command call itself, you can try something like this:

ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" command

I also use "tee" (for visual clarity) and heredoc to send remote bash scripts:

tee << '+++' | ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" bash
  set -x
  echo "hey, your variable is $MYVAR1"
  echo "and your other variable is $MYVAR2"
+++
link|improve this answer
feedback

What is the shell of that user on the server? If it's bash, then ~/.bash_profile or ~/.profile containing all the variables (or something like ". /etc/environment") should work. If it's not bash, consider changing :)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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