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

132

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

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.

Share:
132

Related videos on Youtube

Santosh-Sidd
Author by

Santosh-Sidd

Updated on September 18, 2022

Comments

  • Santosh-Sidd
    Santosh-Sidd over 1 year

    I have a web service that inserts a row into a Database Table.

    enter image description here

    After this a windows service will read this table and updates this table.

    • Inserts a Blob into FILE_IMAGE column
    • STATUS to COMPLETE

    My Web Service has to wait till this table STATUS and FILE_IMAGE column gets updated and then read the FILE_IMAGE.

    My doubt is : What logic is ideal for my web service to wait for the table to get updated. I dont want to use Thread.Sleep or something similar to that. My database is Oracle and code behind is C#.

    • Scott - Слава Україні
      Scott - Слава Україні over 11 years
      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?
    • akostadinov
      akostadinov over 11 years
      yeah, workarounds are possible but inconvenient
  • akostadinov
    akostadinov over 11 years
    crap, I see only -F on command line can help but it's too inconvenient to really use. See bugzilla.mindrot.org/show_bug.cgi?id=1285
  • akostadinov
    akostadinov about 9 years
    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
    akostadinov over 7 years
    See my comment above. if one supplies on command line -F, then the system wide config is ignored according to man page from bugzilla.mindrot.org/show_bug.cgi?id=1285 ; it is an option but not really the desired feature.
  • akostadinov
    akostadinov about 5 years
    See 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
  • Iulian Onofrei
    Iulian Onofrei about 4 years
    And how can you change AcceptEnv to not accept variables send by the client?
  • reinierpost
    reinierpost about 4 years
    This is bloody stupid.