7

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

6 Answers 6

5

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

2
  • 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. Feb 4, 2010 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, 2010 at 10:56
1

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"
+++
1

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 :)

0

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
1
0

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:
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)

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

@Dom (I can't post comment): for me it's working /etc/ssh/sshd_config

AcceptEnv LANG LC_*

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .