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

ChrisInCambo
  • 1,771

6 Answers6

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

Dom
  • 6,793
  • 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 04 '10 at 08: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 04 '10 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"
+++
Duane J
  • 111
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 :)

pitr
  • 577
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)

Christian
  • 4,723
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
Amandasaurus
  • 32,281
  • 69
  • 194
  • 263
0

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

AcceptEnv LANG LC_*
pevik
  • 294
  • 1
  • 12