how to disable SendEnv variables set in ssh_config from ~/.ssh/config

30

8

I couldn't find that anywhere so I'm wondering am I the only one hitting such issue.

By default ssh on Red Hat and Debian at least has a ssh_config with SendEnv option passing LC* and LANG variables in the remote session. If one is not root to change /etc/ssh/ssh_config, how can he disable that behavior? SendEnv option seems to be accumulating and I can't see any way to reset it.

And to avoid being asked, I need to avoid passing my locale to test machines to avoid side effects on scripts and programs that rely on locale being the default for the machine.

akostadinov

Posted 2012-10-09T18:47:00.853

Reputation: 1 140

This is not an answer to your question, but can you solve your problem by invoking the scripts and programs on your test machines through env or with a wrapper script? – Scott – 2012-10-09T20:57:59.507

2yeah, workarounds are possible but inconvenient – akostadinov – 2012-10-10T07:34:24.233

Answers

18

You're not the only one. As documented in ssh_config(5) you can't unset SendEnv, because

Multiple environment variables may be [...] spread across multiple SendEnv directives.

If you have root on the test machines you could change AcceptEnv to not accept variables sent by the client, though.

Ansgar Wiechers

Posted 2012-10-09T18:47:00.853

Reputation: 4 860

4

crap, I see only -F on command line can help but it's too inconvenient to really use. See https://bugzilla.mindrot.org/show_bug.cgi?id=1285

– akostadinov – 2012-10-10T07:30:50.130

5

This can't be done in ~/.ssh/config because SendEnv cannot be overridden.

Using aliases won't work for scripts that call ssh.

One alternative is to export a function. E.g. in ~/.bashrc:

function ssh() {
    LANG="en_US.UTF-8" \
    LC_ADDRESS="$LANG" \
    LC_IDENTIFICATION="$LANG" \
    LC_MEASUREMENT="$LANG" \
    LC_MONETARY="$LANG" \
    LC_NAME="$LANG" \
    LC_NUMERIC="$LANG" \
    LC_PAPER="$LANG" \
    LC_TELEPHONE="$LANG" \
    LC_TIME="$LANG" \
    LC_ALL="$LANG" \
    /usr/bin/ssh $@
}
export -f ssh

Fernando Correia

Posted 2012-10-09T18:47:00.853

Reputation: 303

1

There's option SetEnv, one can force LANG to some specific value before sending it.

Also man page says that

It is possible to clear previously set SendEnv variable names by prefixing patterns with -.

but I didn't manage to make this work.

burunduk3

Posted 2012-10-09T18:47:00.853

Reputation: 11

See https://bugzilla.mindrot.org/show_bug.cgi?id=1285 , probably that will explain why the - approach did not work. Good suggestion though to hardcode remote LANG and other vars in ssh config. Makes things more predictable. Perhaps SetEnv is a newer directive because nobody else suggested about it. SetEnv LANG=en_US.UTF-8

– akostadinov – 2019-05-13T14:31:32.183

0

According to man ssh:

 -F configfile
         Specifies an alternative per-user configuration file.  If a con-
         figuration file is given on the command line, the system-wide
         configuration file (/etc/ssh/ssh_config) will be ignored.  The
         default for the per-user configuration file is ~/.ssh/config.

So, you can ssh without complying with /etc/ssh/ssh_config by explicitly specifying the (default) configuration file on the command line (~/.ssh/config is OK to be empty):

$ touch ~/.ssh/config
$ ssh -F ~/.ssh/config your_user@your_host

You can make an alias for it in ~/.bashrc:

alias ssh="ssh -F ~/.ssh/config"

Restart the bash shell, then you can simply ssh like this:

$ ssh your_user@your_host

Rockallite

Posted 2012-10-09T18:47:00.853

Reputation: 241

See my comment above. if one supplies on command line -F, then the system wide config is ignored according to man page from https://bugzilla.mindrot.org/show_bug.cgi?id=1285 ; it is an option but not really the desired feature.

– akostadinov – 2017-01-23T08:59:53.017

0

If you are using bash you may set up an alias ssh='LANG= command ssh' to disable LANG passing to the other servers.

Tharrrk

Posted 2012-10-09T18:47:00.853

Reputation: 1

0

You can use su - youruser when you are logged in over ssh. This will reinitialize the environment for the user.

Actually you initialize a new session with a new environment.

Lambert

Posted 2012-10-09T18:47:00.853

Reputation: 269

Question is to have environment sane automatically. And btw su is not always installed. And you have to type in your password with su. Not useful. There are easier workarounds. – akostadinov – 2015-04-15T08:46:32.563