Windows – ssh SendEnv from windows to linux server using cygwin

bashrcenvironment-variablesopensusesshwindows

I am doing ssh to a Open SUSE linux server from windows cygwin. I am trying to send one of my local environment variable through the ssh command so that I can load some specific .bashrc file right after logging in. Here is what I have tried with.

Windows Machine has this env variable

IDENTITY=samiron
echo %IDENTITY%
   samiron

In linux machine I have

vim /etc/ssh/sshd_config
AcceptEnv IDENTITY

In /home/user/.bashrc I have written something like

export ME=$IDENTITY

My plan is to have a file like .bashrc.samiron and do source ~/.bashrc.$ME from .bashrc file.

However, I am doing ssh like below and expecting the variable $ME to contain "samiron"

ssh -o SendEnv=IDENTITY user@server.com

But after logging

user@server:~> echo $ME

Its shows nothing. Anyone can suggest me what I am doing wrong here?

Best Answer

These two conditions should be met before it can work as expected:

  1. Your ssh server has to be configured to accept forwarding of variables from local client's environment. As it may be a security risk to allow such behavior it is usually disabled by default. You can enable it by specifying "AcceptEnv" directive in your ssh server configuration. So put something like this to /etc/ssh/sshd_config file and reload the ssh server service (variable names can contain wildcards, you can specify multiple variables separated by whitespaces, details in man sshd_config)

    AcceptEnv VARIABLE_NAME

  2. This feature works for ssh protocol of version 2 only. This is fulfilled almost in all modern Linux distribution by default if it wasn't changed ("Protocol" directive).

Related Topic