'How not to pass the locale through an ssh connection command

I have some aliases for ssh, example:

alias buildWork="ssh work '~/build_app'"

The problem is that the ssh command passes some variables like $LC_CTYPE that causes some errors.

How to prevent that and use the server configurations ?



Solution 1:[1]

It sounds like your SSH client is configured to forward the locale settings. You can prevent this by altering your configuration (the global file is typically /etc/ssh/ssh_config):

# comment out / remove the following line
SendEnv LANG LC_*

Alternatively you can change the configuration of the server, by editing /etc/ssh/sshd_config on the remote machine (note the d in sshd_config):

# comment out / remove the following line
AcceptEnv LANG LC_*

Solution 2:[2]

As already explained in other answers, the client will send all environment variables specified via SendEnv in /etc/ssh/ssh_config. You can also force ssh to not send already defined variable names, using your user's configuration.

From OpenSSH man page:

It is possible to clear previously set SendEnv variable names by prefixing patterns with -. The default is not to send any environment variables.

So, to prevent sending your locale, you can put the following into your ~/.ssh/config:

SendEnv -LC_* -LANG*

Solution 3:[3]

In short:

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

See this answer for details.

Solution 4:[4]

Accepted answer is correct, but, if you don't want to change your config files, you can override specific locale on the command line

LC_TIME="en_US.UTF-8" ssh [email protected]

Solution 5:[5]

To not send our Local Environment (SendEnv) which is the default behaviour since it is specified in /etc/ssh/ssh_config you have to:

  1. Create a config file for your user ~/.ssh/config
  2. Add these lines
Host *
   SendEnv !LANG !LC_*
  1. Reload your shell sudo su - $YourSelf (or logout/login)

a bit of explanation

  • ! == means not
  • * == means all

so

  • !LANG == don't send the variable LANG
  • !LC_* == dont send all variable started with LC_

source: https://bugzilla.mindrot.org/show_bug.cgi?id=1285#c8

Remember that not everyone with this issue will have the power of editing /etc/ssh/ssh_config

Solution 6:[6]

I was facing the issue that I attributed to ssh passing the locale settings, so I tried with disabling it on client site, then on server site as well (as advised above) and still the locale was complaining after logging in.

Turned out to be a messy locale on the destination server itself, where the setting was taken from /etc/default/locale

I had to clean it completely, run # dpkg-reconfigure locales which fixed the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Community
Solution 4 LMC
Solution 5 JOduMonT
Solution 6 remigiusz boguszewicz