How not to pass the locale through an ssh connection command

BashSsh

Bash Problem Overview


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 ?

Bash Solutions


Solution 1 - Bash

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 - Bash

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 - Bash

In short:

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

See this answer for details.

Solution 4 - Bash

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 - Bash

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 - Bash

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.

Solution 7 - Bash

To stop sending Environment Variables via sftp
Tested on CENTOS 7

  • create file config in ~/xyzuser/.ssh/config

  • set permission to 600 ~/xyzuser/.ssh/config

  • Put the following content in the file

    comment the below lines commented to disable env variables#########

  • Send locale-related environment variables SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE SendEnv XMODIFIERS

Running without the ~/xyzuser/.ssh/config sftp -v xyzuser@destinationhost -------------------truncated output-------- debug1: Requesting [email protected] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 debug1: Sending subsystem: sftp

Running with the ~/xyzuser/.ssh/config

sftp -v -F /home/xyzuser/.ssh/config  xyzuser@destinationhost

 ----truncated----------
 debug1: channel 0: new [client-session]
 debug1: Requesting no[email protected]
 debug1: Entering interactive session.
 debug1: Sending subsystem: sftp
 Connected to destinationhost

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSoniqueView Question on Stackoverflow
Solution 1 - BashTom FenechView Answer on Stackoverflow
Solution 2 - BashXoozeeView Answer on Stackoverflow
Solution 3 - BashRockalliteView Answer on Stackoverflow
Solution 4 - BashLMCView Answer on Stackoverflow
Solution 5 - BashJOduMonTView Answer on Stackoverflow
Solution 6 - Bashremigiusz boguszewiczView Answer on Stackoverflow
Solution 7 - BashAzmatView Answer on Stackoverflow